将nginx端口更改为81,但nginx仍然绑定在80端口

问题描述 投票:0回答:1

我正在使用nginx和haproxy,我希望haproxy绑定到端口80,所以我将nginx更改为端口81。但是当我将端口nginx更改为81然后启动nginx时仍然绑定在端口80并出现错误。对我来说有什么解决方案。

这是我的 nginx 配置默认在 /etc/nginx/sites-enabled

##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or Wordpress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
#
server {
    listen 81;
    listen [::]:81;


    # SSL configuration
    #
    # listen 443 ssl default_server;
    # listen [::]:443 ssl default_server;
    #
    # Note: You should disable gzip for SSL traffic.
    # See: https://bugs.debian.org/773332
    #
    # Read up on ssl_ciphers to ensure a secure configuration.
    # See: https://bugs.debian.org/765782
    #
    # Self signed certs generated by the ssl-cert package
    # Don't use them in a production server!
    #
    # include snippets/snakeoil.conf;

    root /var/www/html;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html;

    server_name _;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }

    # pass PHP scripts to FastCGI server
    #
    #location ~ \.php$ {
    #   include snippets/fastcgi-php.conf;
    #
    #   # With php-fpm (or other unix sockets):
    #   fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
    #   # With php-cgi (or other tcp sockets):
    #   fastcgi_pass 127.0.0.1:9000;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #   deny all;
    #}
}


# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
#   listen 80;
#   listen [::]:80;
#
#   server_name example.com;
#
#   root /var/www/example.com;
#   index index.html;
#
#   location / {
#       try_files $uri $uri/ =404;
#   }
#}

还有我的 haproxy 配置

global
    log /dev/log    local0
    log /dev/log    local1 notice
    chroot /var/lib/haproxy
    stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
    stats timeout 30s
    user haproxy
    group haproxy
    daemon

    # Default SSL material locations
    ca-base /etc/ssl/certs
    crt-base /etc/ssl/private

    # Default ciphers to use on SSL-enabled listening sockets.
    # For more information, see ciphers(1SSL). This list is from:
    #  https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/
    # An alternative list with additional directives can be obtained from
    #  https://mozilla.github.io/server-side-tls/ssl-config-generator/?server=haproxy
    ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:RSA+AESGCM:RSA+AES:!aNULL:!MD5:!DSS
    ssl-default-bind-options no-sslv3

defaults
    log global
    mode    http
    option  httplog
    option  dontlognull
        timeout connect 5000
        timeout client  50000
        timeout server  50000
    errorfile 400 /etc/haproxy/errors/400.http
    errorfile 403 /etc/haproxy/errors/403.http
    errorfile 408 /etc/haproxy/errors/408.http
    errorfile 500 /etc/haproxy/errors/500.http
    errorfile 502 /etc/haproxy/errors/502.http
    errorfile 503 /etc/haproxy/errors/503.http
    errorfile 504 /etc/haproxy/errors/504.http
frontend myfrontend
    bind 127.0.0.1:80
    rate-limit sessions 50
    http-response set-header Cache-Control no-cache,\ max-age=600 if { capture.req.uri -m beg /api/ }
    capture request header Host len 32
    acl shipping-report.local hdr(host) -i shipping-report.local www.shipping-report.local/report
    use_backend report_shipping if shipping-report.local
    


backend report_shipping 
    server report01 shipping-report.local:8000

我得到了错误

nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Wed 2022-08-31 16:04:03 +07; 1min 0s ago
     Docs: man:nginx(8)
  Process: 30507 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=1/FAILURE)
  Process: 26443 ExecReload=/usr/sbin/nginx -g daemon on; master_process on; -s reload (code=exited, status=0/SUCCESS)
  Process: 31737 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE)
  Process: 31721 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
 Main PID: 30483 (code=exited, status=0/SUCCESS)

Thg 8 31 16:04:01 falcon-anhnkd systemd[1]: Starting A high performance web server and a reverse proxy server...
Thg 8 31 16:04:01 falcon-anhnkd nginx[31737]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Thg 8 31 16:04:01 falcon-anhnkd nginx[31737]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Thg 8 31 16:04:02 falcon-anhnkd nginx[31737]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Thg 8 31 16:04:02 falcon-anhnkd nginx[31737]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Thg 8 31 16:04:03 falcon-anhnkd nginx[31737]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Thg 8 31 16:04:03 falcon-anhnkd nginx[31737]: nginx: [emerg] still could not bind()
Thg 8 31 16:04:03 falcon-anhnkd systemd[1]: nginx.service: Control process exited, code=exited status=1
Thg 8 31 16:04:03 falcon-anhnkd systemd[1]: nginx.service: Failed with result 'exit-code'.
Thg 8 31 16:04:03 falcon-anhnkd systemd[1]: Failed to start A high performance web server and a reverse proxy server.

我想同时使用 nginx 和 haproxy 有什么解决方案

nginx haproxy nginx-config
1个回答
0
投票

您可能想在此处检查 nginx.conf 和 conf/*.conf 的内容。就我而言,它是conf/目录中的默认文件,正在侦听端口80。希望答案有帮助。

如果您想了解 nginx 与 haproxy 的比较,您可以关注 这篇文章

© www.soinside.com 2019 - 2024. All rights reserved.