简体   繁体   English

Nginx反向代理的设置

[英]Setting Up of Nginx reverse proxy

I have a node application running on an ec2 instance.我有一个在 ec2 实例上运行的节点应用程序。 Node is running on port 5000. I want to access the api from remote.节点在端口 5000 上运行。我想从远程访问 api。 this is nginx configuration file.这是 nginx 配置文件。

    server {
     root /var/www/html;
     index index.html index.htm index.nginx-debian.html;

     client_max_body_size 20M;
     listen 80;
     listen [::]:80;
     location / {
            proxy_pass http://127.0.0.1:5000;
     }
     location /nginx_status {
       # Turn on stats
       stub_status on;
       access_log   off;
     }
    }

when I try to curl using curl localhost/nginx_status it returns当我尝试curl使用curl localhost/nginx_status它返回

    Active connections: 1 
    server accepts handled requests
    11 11 12 
    Reading: 0 Writing: 1 Waiting: 0 

Also when I try to access the IP in browser, it shows此外,当我尝试在浏览器中访问 IP 时,它显示


       Welcome to nginx!

  If you see this page, the nginx web server is successfully installed and working.      Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.

But if I try to access the ip_address/nginx_status it shows 404 Error for example if I took IP address 123.456.789.098 in browser it shows the above mentioned message and if I took 123.456.789.098/nginx_status it will return 404 error.但是,如果我尝试访问 ip_address/nginx_status,它会显示404 Error ,例如,如果我在浏览器中使用 IP 地址123.456.789.098 ,它会显示上述消息,如果我使用123.456.789.098/nginx_status ,它将返回 404 错误。 Even if I try curl ip_address/nginx_status it is also returning 404 error.即使我尝试 curl ip_address/nginx_status它也返回 404 错误。

My question is, How can I access node application running on port 5000 from outside world?我的问题是,如何从外界访问在端口 5000 上运行的节点应用程序?

unfortunately I only see part of your config, is there another server that listens to 80?不幸的是我只看到你配置的一部分,是否有另一台服务器监听 80?

You don't use "default_server" for listen either, and without "server_name" I find it difficult to distinguish between them.您也不使用“default_server”进行监听,如果没有“server_name”,我发现很难区分它们。 So maybe another config with the server + port 80 as default_server takes effect.因此,也许另一个将服务器 + 端口 80 作为 default_server 的配置生效。 Check in your /etc/nginx/ folder which servers {..} all exist.检查您的 /etc/nginx/ 文件夹,其中服务器 {..} 都存在。

The proxy_pass looks correct, if the nodjs server is really listed there, check again whether it is really http or https scheme. proxy_pass 看起来是正确的,如果 nodjs 服务器真的在那里列出,请再次检查它是否真的是 http 或 https 方案。 For the correct protocol transmission of the proxy_pass.用于proxy_pass 的正确协议传输。

But you should then add a control for the "stub_status" so that it is information that you do not entrust to everyone, for me it is the case that only one application has access to it internally and under another list what is not released on the inte.net:但是你应该为“stub_status”添加一个控制,这样你就不会把它委托给每个人,对我来说,只有一个应用程序可以在内部访问它,而在另一个列表下,什么是没有发布的因特网:

server {
    listen 127.0.0.1:10081 default_server;

    location /flyingfish_status {
        stub_status on;
        access_log off;
        allow 127.0.0.1;
        deny all;
    }

}

I'm curious what you find out: :)我很好奇你发现了什么::)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM