简体   繁体   English

Nginx 不监听其他端口,只监听 80 端口

[英]Nginx not listening to other ports only port 80

I have 3 apps:我有 3 个应用程序:

  • The first one listens at port 80第一个监听80端口
  • The second one listens at 8001第二个在8001听
  • The third one listens at 8002第三个在8002听

What happens is only the port 80 is running others are just connecting发生的事情是只有端口 80 正在运行,其他人只是在连接

Here's my codes这是我的代码

port 80.conf端口 80.conf

server {

    listen 80;
    server_name example1.com;
    charset utf-8;
    access_log /var/log/nginx/access.example1.log;
    error_log /var/log/nginx/error.example1.log;

    location /static {
        alias /usr/src/app/static;
    }
    location / {
        proxy_pass http://example1:8000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

}

port8001.conf端口8001.conf

server {

    listen 8001;
    server_name example2.com;
    charset utf-8;
    if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})") {
        set $year $1;
        set $month $2;
        set $day $3;
    }
    access_log /usr/logs/nginx/example1/example2.$year-$month-$day.log;

    location / {
        root /usr/src/example2;
    }
    error_page  405     =200 $uri;
}

port 8002 8002端口

server {

    listen 8002;
    server_name example3.com;
    charset utf-8;

    include /etc/nginx/www-allow/example3-allow.conf;
    deny all;

    if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})") {
        set $year $1;
        set $month $2;
        set $day $3;
    } 
    access_log /usr/logs/nginx/example3/example3.$year-$month-$day.log;

    location / {
        root /usr/src/example3;
    }
}

The funny part here is that I tried making the port81.conf to listen on port 80 and making the listen on the port80.conf into port 8001 and this time my app in port81,conf worked..这里有趣的部分是,我尝试让 port81.conf 监听端口 80 并将 port80.conf 上的监听监听到端口 8001,这次我在 port81,conf 中的应用程序工作了..

So it just means that my server just doesn't allow to be accessed in other ports like example.com:8001所以这只是意味着我的服务器不允许在其他端口(如 example.com:8001)中访问

How can this be resolved?如何解决这个问题?

您是否为端口 8001 和 8002 打开了防火墙?

On my case I'm trying to browse http://{Local machine IP Address}:8080, that is why the page is not shown.就我而言,我试图浏览 http://{Local machine IP Address}:8080,这就是页面未显示的原因。 To my confusion I forgot that I need to get the IP Address of the Docker container.令我困惑的是,我忘记了我需要获取 Docker 容器的 IP 地址。

Here is the docker command for that:这是 docker 命令:

docker exec {docker container id} ipconfig

Then get the IP Address and browse it using this format: http://{Docker container IP Address}:8080然后获取 IP 地址并使用以下格式浏览它:http://{Docker 容器 IP 地址}:8080

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

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