Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trailing Slash issue with ngnix configuration #53

Open
N3evin opened this issue Jan 29, 2021 · 4 comments
Open

Trailing Slash issue with ngnix configuration #53

N3evin opened this issue Jan 29, 2021 · 4 comments

Comments

@N3evin
Copy link
Owner

N3evin commented Jan 29, 2021

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;
}
@Swinkid
Copy link

Swinkid commented Dec 3, 2021

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

@N3evin
Copy link
Owner Author

N3evin commented Dec 4, 2021

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.

@AbandonedCart
Copy link
Contributor

Here are the full details of that solution

and here is a method for working with and without a trailing slash

@N3evin
Copy link
Owner Author

N3evin commented Mar 23, 2023

with and without a trailing slash

Had tried the 1st method, above comments :) But will look into the 2nd method. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants