1
votes

I have a site that uses subdirectories and 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;
}
1
Please add server { } config where rewrite doesn't work.Timofey Stolbov
Added, as well as the includes. I just thought - is the www rewrite the problem? If so, I could modify it to add the slash there, but would it work for URLs that are already including www? Is there a better way to modify it? I need the www check.Shauna

1 Answers

1
votes

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;
}