Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nginx simple proxy_pass to localhost not working

Tags:

nginx

proxy

I'm trying to run a minimalist reverse-proxy, and came up with the following :

events {     worker_connections 4096; }     http {     server {         listen 80;         location / {             proxy_pass http://127.0.0.1:3000/;         }        }    }    

`

However, when I access this server, I get the standard "welcome to nginx page", instead of the response from the server running on port 3000.

If I ssh to the machine and run curl http://127.0.0.1:3000/, I get the desired result (and eventually I ran that server on port 80 and it worked fine, so I know it has to do with the reverse proxy config).

like image 530
agam Avatar asked Mar 11 '13 09:03

agam


People also ask

How do you check if nginx reverse proxy is working?

To check the status of Nginx, run systemctl status nginx . This command generates some useful information. As this screenshot shows, Nginx is in active (running) status, and the process ID of the Nginx instance is 8539.

What is proxy_pass in nginx?

The proxy_pass setting makes the Nginx reverse proxy setup work. The proxy_pass is configured in the location section of any virtual host configuration file. To set up an Nginx proxy_pass globally, edit the default file in Nginx's sites-available folder.

Why use nginx reverse proxy?

Security and anonymity – By intercepting requests headed for your backend servers, a reverse proxy server protects their identities and acts as an additional defense against security attacks.


2 Answers

I had exactly the same problem. I just commented out a line in my nginx.conf file:

 include /etc/nginx/sites-enabled/*; 

changed to

 #include /etc/nginx/sites-enabled/*; 
like image 185
Vijay Boyapati Avatar answered Sep 26 '22 06:09

Vijay Boyapati


Explainng Vijay's post via an answer since exchange will not let me comment yet.

Commenting out the sites-enabled directory is probably required because you are using the standard nginx.conf file. You will notice that line is already within the http directive. If you are using the standard configuration, you are redefining an http directive within another http directive. You could also update your site file to only have the server directive and not the http directive.

Standard-ish nginx.conf file:

worker_processes  4;  error_log  /var/log/nginx/error.log; pid        /var/run/nginx.pid;  events {   worker_connections  1024; }  http {    include       /etc/nginx/mime.types;   default_type  application/octet-stream;    access_log    /var/log/nginx/access.log;    sendfile on;   tcp_nopush on;   tcp_nodelay on;    keepalive_timeout  65;    gzip  on;   gzip_http_version 1.0;   gzip_comp_level 5;   gzip_proxied any;   gzip_vary off;   gzip_types text/plain text/css application/x-javascript text/xml application/xml application/rss+xml application/atom+xml text/javascript application/javascript application/json text/mathml;   gzip_min_length  1000;   gzip_disable     "MSIE [1-6]\.";    server_names_hash_bucket_size 64;   types_hash_max_size 2048;   types_hash_bucket_size 64;   client_max_body_size 1024;    include /etc/nginx/conf.d/*.conf;   include /etc/nginx/sites-enabled/*; } 

example compatiable site file within sites-enabled:

server {     server_name {server name};     listen 80;     access_log /var/log/nginx/access.log;     error_log /var/log/nginx/error.log;     location / {         proxy_pass http://example.com:8080;         proxy_set_header Host $host;     } } 
like image 38
MonomiDev Avatar answered Sep 24 '22 06:09

MonomiDev