问答

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

作者:admin 2021-04-21 我要评论

当我配置好nginx中负载均衡的ip及端口后,发现配置文件中配置的端口8888被nginx占用(如下图) 所以在启动java项目时因端口被占用而无法启动(如下图) 请大家帮...

在说正事之前,我要推荐一个福利:你还在原价购买阿里云、腾讯云、华为云服务器吗?那太亏啦!来这里,新购、升级、续费都打折,能够为您省60%的钱呢!2核4G企业级云服务器低至69元/年,点击进去看看吧>>>)

当我配置好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 {
        }
    }
}

###

换端口

 server {
        listen       8889;
        server_name  localhost;

版权声明:本文转载自网络,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。本站转载出于传播更多优秀技术知识之目的,如有侵权请联系QQ/微信:153890879删除

相关文章
  • 如何解决nginx占用了配置文件中的端口

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

  • segmentation fault from ctags in MIN

    segmentation fault from ctags in MIN

  • python使用selenium启动chrome报错,错

    python使用selenium启动chrome报错,错

  • prerender-spa-plugin怎么搭配vue-i18n

    prerender-spa-plugin怎么搭配vue-i18n

腾讯云代理商
海外云服务器