开发者

Nginx isn't liking rewrite

开发者 https://www.devze.com 2023-02-22 07:25 出处:网络
I have a site that uses subdirectories a开发者_运维技巧nd currently only works when the trailing slash is added to the URL (\"http://www.domain.com/dir/\"). When there is no trailing slash, I get \"un

I have a site that uses subdirectories a开发者_运维技巧nd currently only works when the trailing slash is added to the URL ("http://www.domain.com/dir/"). When there is no trailing slash, I get "unable to connect at server domain.com:8080" (8080 is the listening port Nginx is set up for).

I've tried adding the rewrite suggested here (and here), but it results in the "cannot connect" error for the entire virtual host.

Is there another way to add the trailing slash that I could try? Or, is there a way I can configure it to see the URL as a directory (and thus, look for the index file), regardless of the presence of the trailing slash?

Edit

Nginx.conf:

user www-data;
worker_processes  4;

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

events {
    worker_connections  1024;
    # multi_accept on;
}

http {
    include       /etc/nginx/mime.types;

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

    sendfile        on;
    tcp_nopush     on;
    tcp_nodelay        on;

    gzip  on;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";

    map $scheme $fastcgi_https { ## Detect when HTTPS is used
        default off;
        https on;
    }

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

Server block:

server {
        listen 8080;
        server_name domain.com www.domain.com;
        include www.inc;

        root /var/vhosts/domain/current/frontend/;
        include php.inc;
}

Php.inc:

index index.php;

location ~ \.php$ {
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    #fastcgi_param  ENVIRONMENT production;
    fastcgi_param HTTPS $fastcgi_https;
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    #fastcgi_intercept_errors on;
    fastcgi_connect_timeout 10;
    fastcgi_send_timeout 15;
    fastcgi_read_timeout 120;
    fastcgi_buffer_size 128k;
    fastcgi_buffers 4 256k;
    fastcgi_busy_buffers_size 256k;
    fastcgi_temp_file_write_size 256k;
    include fastcgi_params;
}

www.inc:

if ($host ~ ^([^\.]+\.com)) {
    rewrite ^/(.*)$ http://www.$host/$1 permanent;
}


Change server {} block to

server {
    listen 8080;
    port_in_redirect off;
    server_name www.domain.com domain.com; #Order matters!
    include www.inc;

    root /var/vhosts/domain/current/frontend/;
    include php.inc;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号