AmiiboAPI icon indicating copy to clipboard operation
AmiiboAPI copied to clipboard

Trailing Slash issue with ngnix configuration

Open N3evin opened this issue 4 years ago • 4 comments

I will be posting my Nginx configuration to see if anyone can help solve this issue. Seems like it will add a trailing slash when and cause a redirect loop.

server {
    listen 80;
    listen [::]:80;
    server_name amiiboapi.com www.amiiboapi.com;

    location / {
        add_header 'Access-Control-Allow-Origin' '*' always;
    	return 301 https://$server_name$request_uri;
    }
}

server {
    listen 443 ssl;
    server_name amiiboapi.com www.amiiboapi.com;

    location /api(.*)$ {
    	limit_req zone=mylimit;
    	proxy_pass http://client:8080/api$1$is_args$args;
        proxy_redirect     off;
        proxy_set_header   Host $host;
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Host $server_name;
    }

    location / {
        proxy_pass http://client:8080;
        proxy_redirect     off;
        proxy_set_header   Host $host;
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Host $server_name;
    }

    ssl_certificate /etc/letsencrypt/live/certification.pem;
    ssl_certificate_key /etc/letsencrypt/live/key.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}

N3evin avatar Jan 29 '21 04:01 N3evin

Could add rewrite ^/(.*)/$ /$1 permanent; to your server block if this is still an issue?

Swinkid avatar Dec 03 '21 12:12 Swinkid

Could add rewrite ^/(.*)/$ /$1 permanent; to your server block if this is still an issue?

Just tried that, seems to not work. Kinda cause the site to crash too.

Below are the 2 different methods I tried with the rewrite.

  1. Added on both server blocks.
  2. Added only to 443 listener.

N3evin avatar Dec 04 '21 06:12 N3evin