Nginx reverse proxy to apache adds a trailing slash at the end

March 29, 2019 288 views
Nginx Apache Ubuntu 18.04

I have an nginx reverse proxy set up like this:

/etc/nginx/sites-available/domain.com

server {
        listen 80;
        listen [::]:80;

        root /var/www/html;
        index index.html index.htm index.nginx-debian.html;

        server_name domain.com www.domain.com;

        location / {
        proxy_pass http://localhost:8090;
        autoindex on;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
        }

}

The site is on Apache, which is listening on port 8090.

So, /etc/apache2/ports.conf looks like this:

Listen 8090

<IfModule ssl_module>
        Listen 443
</IfModule>

<IfModule mod_gnutls.c>
        Listen 443
</IfModule>

It works, but a trailing slash is added. So I can see my website at domain.com//

I'm not sure if it's nginx or apache causing the trailing extra slash at the end. How can I fix this?

1 Answer

Hello,

this would be from the Nginx Configuration for sure, this is a know issues with it. Most probably you've added a trailing slash somewhere along the way.

Please check your Nginx configuration file for the domain and make sure there is no trailing slash when doing rewrites such as :

Rewrite ^(.*)$ https://$servername.mydomain.com/$1;

or

server_name domain.com/ www.domain.com/;

Another problematic area might be:

 location / {
        proxy_pass http://localhost:8090/;

I know you've provided us with an example configuration file but please take another look to the exact domain's file and make sure there are no leftover trailing slashes.

Have another answer? Share your knowledge.