简体   繁体   中英

Nginx not listening to other ports only port 80

I have 3 apps:

  • The first one listens at port 80
  • The second one listens at 8001
  • The third one listens at 8002

What happens is only the port 80 is running others are just connecting

Here's my codes

port 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

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

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..

So it just means that my server just doesn't allow to be accessed in other ports like 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. To my confusion I forgot that I need to get the IP Address of the Docker container.

Here is the docker command for that:

docker exec {docker container id} ipconfig

Then get the IP Address and browse it using this format: http://{Docker container IP Address}:8080

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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