LINUX.ORG.RU

История изменений

Исправление CYB3R, (текущая версия) :

nginx.conf

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    gzip  on;
    gzip_http_version 1.1;
    gzip_comp_level 2;
    gzip_types    text/plain text/css application/pdf
                  application/x-javascript text/xml
                  application/xml application/xml+rss
                  text/javascript;

    #include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}
Мой сайт:
server {
    server_name  www.golovin.in;
    rewrite ^(.*) http://golovin.in$1 permanent;
}

server {

        listen   80; ## listen for ipv4
        listen   [::]:80 default ipv6only=on; ## listen for ipv6

        server_name  golovin.in;

        access_log  /var/log/nginx/homepage.access.log;

        rewrite ^(.*)\.html$ $1 permanent;
        rewrite ^(.*)/index$ $1 permanent;
        try_files $uri.html $uri/ =404;

        location / {
                root   /var/www/homepage;
                index  index.html;
        }

        error_page  404  /err/404.html;
        error_page  403  /err/403.html;
        location ^~ /err/ {
                internal;
                root  /var/www/homepage; 
        }
        location ~ /err {
                deny    all;
                return  403;
        }

        # redirect server error pages to the static page /50x.html
        #
        #error_page   500 502 503 504  /50x.html;
        #location = /50x.html {
        #       root   /var/www/nginx-default;
        #}

}
Интересны тут только эти строчки:
rewrite ^(.*)\.html$ $1 permanent;
rewrite ^(.*)/index$ $1 permanent;
try_files $uri.html $uri/ =404;
Похоже, что у меня ужасные дела с регэкспами.
Подозреваю, что location /err тоже можно было попроще написать.

Исходная версия CYB3R, :

nginx.conf

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    gzip  on;
    gzip_http_version 1.1;
    gzip_comp_level 2;
    gzip_types    text/plain text/css application/pdf
                  application/x-javascript text/xml
                  application/xml application/xml+rss
                  text/javascript;

    #include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}
Мой сайт:
server {
    server_name  www.golovin.in;
    rewrite ^(.*) http://golovin.in$1 permanent;
}

server {

        listen   80; ## listen for ipv4
        listen   [::]:80 default ipv6only=on; ## listen for ipv6

        server_name  golovin.in;

        access_log  /var/log/nginx/homepage.access.log;

        rewrite ^(.*)\.html$ $1 permanent;
        rewrite ^(.*)/index$ $1 permanent;
        try_files $uri.html $uri/ =404;

        location / {
                root   /var/www/homepage;
                index  index.html;
        }

        error_page  404  /err/404.html;
        error_page  403  /err/403.html;
        location ^~ /err/ {
                internal;
                root  /var/www/homepage; 
        }
        location ~ /err {
                deny    all;
                return  403;
        }

        # redirect server error pages to the static page /50x.html
        #
        #error_page   500 502 503 504  /50x.html;
        #location = /50x.html {
        #       root   /var/www/nginx-default;
        #}

}
Интересны тут только эти строчки:
rewrite ^(.*)\.html$ $1 permanent;
rewrite ^(.*)/index$ $1 permanent;
try_files $uri.html $uri/ =404;
Похоже, что у меня ужасные дела с регэкспами.