Nginx/Strapi #5802

This discussion has been migrated from our Github Discussion #5802


jeremy-hubsy236d ago

Hello,

I’ve been trying for two days to configure my nginx proxy with strapi…

I got a 404, 500, 502…read Nginx documentation, read the article on medium from @pierreburgy, ask th community on slack but I can’t find any solution…

Is there any clear config that work to deploy any project with the proxy_pass?

Here is my cofiguration in: sudo nano /etc/nginx/sites-available/my-domain

With this configuration I get a 502.

 server {
    listen 80;
    listen [::]:80;
    server_name syncly.eu;
    location / {
     proxy_set_header X-Forwarded-For $remote_addr;
     proxy_set_header Host $http_host;
     proxy_pass http://localhost:1337;
    }
}

With the default one from DIgitalOcean on “How To Install Nginx on Ubuntu 18.04”

I get “Success! The example.com server block is working!” with:

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

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

  location / {
         try_files $uri $uri/ =404;
    }
 
}

I know that’s a problem with my root but I can’t figure out what do I have to change.

Is there anyone having the same problem?

Your suggestions for this topic
Adding a clear config in the strapi documentation to use NGINX.

Responses to the discussion on Github


derrickmehaffy236d ago

Collaborator

Please see this documentation relating to Nginx: strapi/nginx-proxy.md at 22c93d1040857d1a959554f49bc413c23ff075a0 · strapi/strapi · GitHub

(PR Merged already but docs have not been deployed yet)


derrickmehaffy236d ago

Collaborator

As for sub-folder based proxying, it’s not currently supported but a change for that has already been purposed here: #5724

Once that PR is merged, I will be adding additional documentation for it


jeremy-hubsy236d ago

Author

@derrickmehaffy Thanks a lot I haven’t seen this documentation…

I’ll try right now and try to figure out what was the problem.


jeremy-hubsy236d ago

Author

@derrickmehaffy I try with the new configuration and i’m stiil having a 502 gateway.

Here is my config and the error_log.

I can’t find where this error comes from…

/etc/nginx/sites-available/syncly.eu

server {
    # Listen HTTP
    server_name syncly.eu www.syncly.eu;

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


}

server {
   error_log /home/dev/logs/error_log/error;
    # Listen HTTP
    listen 443 ssl; # managed by Cerbot
    server_name syncly.eu www.syncly.eu;

    # SSL config
    ssl_certificate /etc/letsencrypt/live/syncly.eu/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/syncly.eu/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

    # Proxy Config
    location / {
        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;
    }
}

/etc/nginx/conf.d/upstream.conf

upstream strapi {
    server 127.0.0.1:1337;
}

[error] 11907#11907: *127 connect() failed (111: Connection refused) while connecting to upstream, client: 92.170.114.14,

[error] 11907#11907: *129 connect() failed (111: Connection refused) while connecting to upstream, client: 92.170.114.14,

[error] 18819#18819: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 92.170.114.14,

 18819#18819: *4 connect() failed (111: Connection refused) while connecting to upstream, client: 92.170.114.14,

derrickmehaffy236d ago

Collaborator

502 is a gateway failure meaning Nginx can’t connect to Strapi


jeremy-hubsy236d ago

Author

Thanks Derrick I’ll try to find why.


coderdix211d ago

did you ever find this out - i’ve been trying for a month to get this working and nothing i do works. stuck with 404 on
/admin/runtime~main.90b07e82.js
/admin/main.27aeaeba.chunk.js

i’m gonna get chunked on this project if i dont figure a solution soon


flofleche236d ago

Hi, I did setup Strapi on local with Nginx for my personal project and it worked fine.
However to make it work with https through a proxy I had to declare in strapi config files the address for the proxy route like the following :

#src/config/environments/[current_mode_being_used]/server.json

{
  "host": "localhost",
  "port": 1337,
  "proxy": {
    "enabled": true,
    "ssl": true,
    "host": "www.mystrapi.test",
    "port": 443
  },
  "cron": {
    "enabled": false
  },
  "admin": {
    "autoOpen": false
  }
}

Could this help or you’ve been already doing it like so ?


jeremy-hubsy233d ago

Author

Hi @flofleche

Thanks for your help.

It was a problem between NGINX and Strapi as @derrickmehaffy said.

I delete everything and restart and it was working. I don’t know where was the bug.

As a footnote to the above response, the config referenced here is not correct, please see: Strapi’s documentation | Strapi Documentation

I am not able to configure strapi server with nginx. Please provide clear configurations.