如何解决nginx占用了配置文件中的端口问题?

发布于 2022-09-12 22:39:22 字数 3635 浏览 31 评论 0

当我配置好nginx中负载均衡的ip及端口后,发现配置文件中配置的端口8888被nginx占用(如下图)
image.png
所以在启动java项目时因端口被占用而无法启动(如下图)
image.png
请大家帮忙看下是啥问题导致的?
nginx.conf具体配置如下:

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
worker_rlimit_nofile 20480;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 8192;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   120;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;
    client_header_buffer_size 512k;                                                                                                            
    large_client_header_buffers 4 512k;
    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;
    
    upstream mes {
        server 10.1.42.12:8080 max_fails=10 fail_timeout=60s;
        server 10.1.42.13:8080 max_fails=10 fail_timeout=60s;
        #ip_hash;
    }
    upstream demo {
        server 10.1.42.12:8888 max_fails=10 fail_timeout=60s;
        server 10.1.42.13:8888 max_fails=10 fail_timeout=60s;
        #ip_hash;
    }

    server {
        listen       8080;
        server_name  10.1.42.13;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location /mes-bz-web-login/ {
            # root   html;
            # index  main.html index.html;
            proxy_pass http://mes;
            proxy_set_header Host $host:$server_port;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            client_max_body_size 100m;
            proxy_read_timeout 1800;
        }

        location / {
        }

        error_page 404 /404.html;
        location = /404.html {
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }
    }

    server {
        listen       8888;
        server_name  localhost;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location /mes/ {
            # root   html;
            # index  main.html index.html;
            proxy_pass http://mes;
            proxy_set_header Host $host:$server_port;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            client_max_body_size 100m;
            proxy_read_timeout 1800;
        }

        location / {
        }

        error_page 404 /404.html;
        location = /404.html {
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

香橙ぽ 2022-09-19 22:39:22

换端口

 server {
        listen       8889;
        server_name  localhost;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文