Nginx 不会监听 ipv4 端口 443

Nginx 不会监听 ipv4 端口 443

Nginx 不会监听 ipv4 端口 443。它会监听 ipv4/6 端口 80 和 ipv6 端口 443,但不监听 ipv4 端口 443。

Debian Stretch 9.8 - 当前已更新

使用 apt 安装 nginx-full 包

root@loadbalance01:/etc/nginx# nginx -v
nginx version: nginx/1.10.3

完成后:

systemctl stop nginx
systemctl start nginx

root@loadbalance01:/etc/nginx# !166
netstat -anop | grep LISTEN | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      13533/nginx: master  off (0.00/0/0)
tcp6       0      0 :::80                   :::*                    LISTEN      13533/nginx: master  off (0.00/0/0)
tcp6       0      0 :::443                  :::*                    LISTEN      13533/nginx: master  off (0.00/0/0)

明显缺失的是 TCP 上的端口 443。

只是为了确保没有其他东西在监听 tcp 443

root@loadbalance01:/etc/nginx# netstat -anop | grep LISTEN | grep ':443'
tcp6       0      0 :::443                  :::*                    LISTEN      13533/nginx: master  off (0.00/0/0)

不,只有 tcp6。

/var/log/nginx/error.log 中的唯一错误是已被更正的旧错误。

nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

我的配置:

我只是想创建一个具有 1 个节点的简单负载均衡器,直到我可以证明它的工作原理。

nginx.conf 注意,这只能通过删除 sites-enabled 行来进行修改,我正在使用 conf.d 配置。

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
}

唯一修改的其他文件是:

root@loadbalance01:/etc/nginx# cat conf.d/loadbalance.conf

upstream example {
    server 192.168.1.250;
}

server {
    server_name example.com

    listen 443 ssl;
    listen [::]:443 ssl;

    ssl on;

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

    location / {
        proxy_pass http://example;
    }
}

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    server_name _;

    return 301 https://example.com;
}

注意:重命名为 example.com

答案1

感谢 Alexy Ten,

配置中服务器名称指令后缺少一个分号。它通过了语法检查,但仍然是错误的。

谢谢

答案2

我对 nginx 的使用经验并不丰富,但我曾成功使用以下配置文件进行反向代理/负载平衡。希望本文能对你有所帮助

# HTTP Server redirect to HTTPS
server {
    listen 80;
    server_name <WEB_NAME>.example.com;
    return 301 https://$host$request_uri;
}

# HTTPS Server
server {
    listen 443;
    server_name <WEB_NAME>.example.com;

    # It is best to place the root of the server block at the server level, and not the location level
    # any location block path will be relative to this root. 
    root /site/<WEB_NAME>;

    access_log /var/log/nginx/<WEB_NAME>.access.log;
    error_log /var/log/nginx/<WEB_NAME>.error.log;

    ssl on;
    ssl_certificate /etc/nginx/ssl/<WEB_NAME>/example.com.cer;
    ssl_certificate_key /etc/nginx/ssl/<WEB_NAME>/example.com.nopass.key;
    ssl_protocols TLSv1.1 TLSv1.2; # don't use SSLv3 ref: POODLE
    ssl_session_cache  builtin:1000  shared:SSL:10m;
    ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
    ssl_prefer_server_ciphers on;


    location / {
        proxy_pass http://backend/;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $http_host;

        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forward-Proto http;
        proxy_set_header X-Nginx-Proxy true;

        proxy_redirect off;
    }
}


# Uncomment other server entries if Loadbalance Configuration is required
upstream backend {
    server 127.0.0.1:80;
#    server <BACKEND_SERVER2>:<PORT>;
#    server <BACKEND_SERVER3>:<PORT>;
}

**注意:也重命名为 example.com;)

答案3

在我的案例中,Lightsail 上的实例网络级别阻止了 443。必须转到其设置并允许它。

相关内容