nginx reverse proxy not working on http

2019-07-27 06:40发布

I wanted to access my website available at http://localhost:4000, via nginx reverse proxy from external IP address(not on my network)

I have enabled TCP port forwarding on my home router and forwarding port 80 to port 80.

When I try to access my website as http://my.public.ip OR http://my.public.ip:80, page doesn't load. (I did try forwarding actual port 4000 on router and http://my.public.ip:4000, site loaded fine)

What could be missing.

Below is my ngnix conf:

#user  nobody;
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    send_timeout 1800;
    sendfile        on;
    keepalive_timeout  6500;
    server {
        listen  80;
        location / {
          proxy_pass          http://localhost:4000;
          proxy_set_header    Host             $host;
          proxy_set_header    X-Real-IP        $remote_addr;
          proxy_set_header    X-Forwarded-For  $proxy_add_x_forwarded_for;
          proxy_set_header    X-Client-Verify  SUCCESS;
          proxy_set_header    X-Client-DN      $ssl_client_s_dn;
          proxy_set_header    X-SSL-Subject    $ssl_client_s_dn;
          proxy_set_header    X-SSL-Issuer     $ssl_client_i_dn;
          proxy_read_timeout 1800;
          proxy_connect_timeout 1800;
        }
    }
    # HTTPS server

    server {
        listen       443;
        server_name  localhost;

        ssl                  on;
        ssl_certificate      server.crt;
        ssl_certificate_key  server.key;
        ssl_session_timeout  5m;

        ssl_protocols  SSLv2 SSLv3 TLSv1;
        ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
        ssl_prefer_server_ciphers   on;

        location / {
          proxy_pass          http://localhost:3000;
          proxy_set_header    Host             $host;
          proxy_set_header    X-Real-IP        $remote_addr;
          proxy_set_header    X-Forwarded-For  $proxy_add_x_forwarded_for;
          proxy_set_header    X-Client-Verify  SUCCESS;
          proxy_set_header    X-Client-DN      $ssl_client_s_dn;
          proxy_set_header    X-SSL-Subject    $ssl_client_s_dn;
          proxy_set_header    X-SSL-Issuer     $ssl_client_i_dn;
          proxy_read_timeout 1800;
          proxy_connect_timeout 1800;
        }
    }
}

标签: nginx proxy
1条回答
看我几分像从前
2楼-- · 2019-07-27 07:16

If you want to accept with IP address instead of domain name, you can define default server_name like this:

...
http {
    ...
    server {
        listen  80;
        server_name _ ;
        location / {
            ...
        }
    }
    ....
}
查看更多
登录 后发表回答