Question

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

Posted March 29, 2019 6.4k views
NginxApacheUbuntu 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?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
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.