2
I’ve had a problem for a while and I can’t fix it. The problem is this:
I have a server that has an api running PM2 on it at port 3000. I installed NGINX and am trying to link the route of my domain + path to perform the requests for api. I’d like to use a route similar to:
www.dominio.com.br/api
But I cannot configure NGINX to do this.
I set up NGINX this way:
location / {
proxy_pass http://localhost:3000;
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;
}
And so it works, but with the route as follows:
www.dominio.com.br
I tried to put the /api
in the complement of Location, thus:
location /api {
OR
location /api/ {
but it didn’t work..
I tried tbm to use upstream and it didn’t work! I set it up this way:
upstream teste_api {
server http://localhost:3000;
}
location /api {
set $upstream teste_api;
}
And when I ran the command: sudo Nginx -t
This error is presented: [emerg] "upstream" directive is not allowed here in /etc/nginx/sites-enabled/default:20
Somebody please help me?
Basically in the latest versions you would need to upstream normally in the configuration file (or part) and in your host file (or virtual) do the proxy_pass. Formless which version of Nginx vc uses?
– Lauro Moraes
Nginx version: Nginx/1.14.0 (Ubuntu)! Apparently upstream is not being recognized in the configuration file.
– Guilherme Nunes
You could edit your question and add the excerpt from your upstream. Let tbm know if you get an error running the command: sudo Nginx -t
– Lauro Moraes
From what I’ve seen it’s a permission error! That’s right?
– Guilherme Nunes
I believe, you need to remove the directive upstream out of the server block. It’s in your block server {}? This directive (upstream) must be allocated in the block http{}
– Lauro Moraes
Yes, it’s inside the server block! I’m going to do a test by placing it inside the http block. Location is inside http tbm?
– Guilherme Nunes
Unfortunately tbm did not work, the error was now: [emerg] "http" Directive is not allowed here in /etc/Nginx/sites-enabled/default:1
– Guilherme Nunes
Location/api should be inside the server block ... try to follow the example of the response I added and a feedback of what is resulting
– Lauro Moraes