documentation icon indicating copy to clipboard operation
documentation copied to clipboard

[Bug]: Nginx config in subfolder split is invalid

Open mariokandut opened this issue 3 years ago • 1 comments

Link to the documentation page or resource

https://docs.strapi.io/developer-docs/latest/setup-deployment-guides/deployment/optional-software/nginx-proxy.html#nginx-virtual-host

Describe the bug

The settings for NGINX subfolder split are incorrect. Nginx doesn't allow same location used twice.

` ...

Static Root

location / {
    root /var/www/html;
}

# Proxy Config
location / {

... `

The documentation in version 3.x states:

` server { # Listen HTTP listen 80; server_name example.com;

# Redirect HTTP to HTTPS
return 301 https://$host$request_uri;

}

server { # Listen HTTPS listen 443 ssl; server_name example.com;

# SSL config
ssl_certificate /path/to/your/certificate/file;
ssl_certificate_key /path/to/your/certificate/key;

# Static Root
location / {
    root /var/www/html;
}

# Strapi API
location /api/ {
    rewrite ^/api/(.*)$ /$1 break;
    proxy_pass http://strapi;
    proxy_http_version 1.1;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Server $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-Proto $scheme;
    proxy_set_header Host $http_host;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
    proxy_pass_request_headers on;
}

# Strapi Dashboard
location /dashboard {
    proxy_pass http://strapi/dashboard;
    proxy_http_version 1.1;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Server $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-Proto $scheme;
    proxy_set_header Host $http_host;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
    proxy_pass_request_headers on;
}

} `

Additional context

No response

Suggested improvements or fixes

Update example for NGINX on v4 documentation.

Related issue(s)/PR(s)

No response

mariokandut avatar Jan 17 '22 13:01 mariokandut

Yup your right, I completely missed this while I was writing it

derrickmehaffy avatar Jan 18 '22 23:01 derrickmehaffy

Thank you for reporting this and apologies it took so long to get an answer from the Strapi documentation team. @derrickmehaffy Do you know how we could update the Nginx proxy docs or should I discuss this with some other engineers?

pwizla avatar Oct 25 '23 09:10 pwizla

We removed this example completely as it's honestly not recommend. It got removed quite a while ago.

derrickmehaffy avatar Oct 25 '23 12:10 derrickmehaffy

@derrickmehaffy, what is the recommendation the for using with NGINX?

mariokandut avatar Oct 25 '23 13:10 mariokandut

One of the other two examples in the current documentation. Ideally using a subdomain is highly advised.

derrickmehaffy avatar Oct 25 '23 22:10 derrickmehaffy

I'm gonna go ahead and close this one as we do not plan to readd this documentation as we do not support sub-folder splitting, it's not just a bad practice with Strapi but anti-pattern in general.

derrickmehaffy avatar Oct 25 '23 22:10 derrickmehaffy