Unable to resolve localhost with nginx
August 16, 2020 09:55PM
I have a weird problem with nginx

I have a node server running in port 3000 and other in port 3001.

I am testing my app locallly.

My main api run in port 3001. All resources using the api on this port works well using nginx.

I have other api running in port 3000. Here is the problem.
I am able to access a resource if test using the browser address bar:

http://localhost:3000/domapi/hello

But if I use https://gestan1.myapp.local/domapi/hello, I get the next error in nginx log:

2020/08/16 22:11:22 [error] 2500#11700: *4 no resolver defined to resolve localhost, client: 127.0.0.1, server: gestan1.myapp.local, request: "GET /domapi/hello HTTP/1.1", host: "gestan1.myapp.local"


If I replace in nginx:

proxy_pass http://localhost:3000$request_uri;
to `proxy_pass http://127.0.0.1:3000$request_uri;`
all works well.


if I put a "resolver 127.0.0.1;" make no difference. The error appears.
This problem doesn´t happend with api in node server running in 3001 port.

My windows hosts file is:

...
127.0.0.1 gestan1.myapp.local
127.0.0.1 gestan2.myapp.local

//nginx conf

worker_processes 2;
error_log logs/error.log notice;
events {
worker_connections 1024;
}

http {
rewrite_log on;
include mime.types;
default_type application/octet-stream;
sendfile on;
# Enable SSL
ssl_certificate ../ssl/cert.pem;
ssl_certificate_key ../ssl/key.pem;
....
server {
listen 80;
listen [::]:80;
return 301 https://$host$request_uri;
}
include sites-available/*.conf;
}

//folder: sites-available
//file: gestan1.conf;
server {
listen 443 ssl;
server_name gestan1.myapp.local;

#folder vue com index.html - comumn a todos nao muda
include proxy_static.locations;

//this is not working if not using IP number in localhost
location ~ ^/(domapi|otherapi)/ {
#access_log off;
#resolver 127.0.0.1; make no difference
proxy_pass http://localhost:3000$request_uri;
}

#this is working
location ~ ^/(api|uploads|public)/ {
#access_log off;
proxy_pass http://localhost:3001$request_uri;
}

}
//file: proxy_static.locations
location / {
access_log off;
root ../gestan-cloud/dist;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}

location ~ /\.well-known {
allow all;
}

location /.well-known/acme-challenge/ {
root ../ssl;
try_files $uri =404;
}
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 121
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready