同一 IP 上的多个域名的 Nginx SSL 配置

同一 IP 上的多个域名的 Nginx SSL 配置

我用同一个 IP 为多个域名提供服务。我为其中一个域名 (ssobczak.net) 启用了 SSL,但现在我被重定向了,无法访问该域名。

我被重定向到另一个:beta.coralnotes.com(按字母顺序排列,这是该机器上托管的第一个域名)。

> curl -i https://ssobczak.net:443/
HTTP/2 301 
location: http://beta.coralnotes.com/
(...)

配置:

# /etc/nginx/sites-available/ssobczak.net
server {
    server_name ssobczak.net;
    listen *:443 ssl;
    listen [::]:443 ssl;

    root /usr/share/nginx/www/ssobczak.net;
    index index.php index.html;

    access_log /var/log/nginx/ssobczak.net.access.log;
    error_log /var/log/nginx/ssobczak.net.error.log debug;

    (... a few location {...} blocks here ...)

    ssl_certificate /etc/letsencrypt/live/ssobczak.net/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/ssobczak.net/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}

# /etc/nginx/sites-available/beta.coralnotes.com    
server {
    server_name beta.coralnotes.com;
    listen *:80;       

    root /usr/share/nginx/www/beta.coralnotes;
    index index.php;

    access_log /var/log/nginx/beta.coralnotes.com.access.log;
    error_log /var/log/nginx/beta.coralnotes.com.error.log debug;

    (... gzip config ...)
    (... a few location {...} blocks ...)

    # BEGIN W3TC Page Cache cache
    (...)
    # END W3TC Page Cache core

}

执行时我看到的日志条目curl -i https://ssobczak.net:443/

==> /var/log/nginx/error.log <==
2018/12/15 14:19:27 [debug] 20623#20623: accept on 0.0.0.0:80, ready: 0
2018/12/15 14:19:27 [debug] 20623#20623: posix_memalign: 000000000101FB70:512 @16
2018/12/15 14:19:27 [debug] 20623#20623: *2 accept: 141.101.104.185:15076 fd:19
2018/12/15 14:19:27 [debug] 20623#20623: *2 event timer add: 19: 60000:1544883627407
2018/12/15 14:19:27 [debug] 20623#20623: *2 reusable connection: 1
2018/12/15 14:19:27 [debug] 20623#20623: *2 epoll add event: fd:19 op:1 ev:80002001
2018/12/15 14:19:27 [debug] 20623#20623: *2 http wait request handler
2018/12/15 14:19:27 [debug] 20623#20623: *2 malloc: 0000000001212470:1024
2018/12/15 14:19:27 [debug] 20623#20623: *2 recv: eof:0, avail:1
2018/12/15 14:19:27 [debug] 20623#20623: *2 recv: fd:19 290 of 1024
2018/12/15 14:19:27 [debug] 20623#20623: *2 reusable connection: 0
2018/12/15 14:19:27 [debug] 20623#20623: *2 posix_memalign: 00000000010314A0:4096 @16
2018/12/15 14:19:27 [debug] 20623#20623: *2 http process request line
2018/12/15 14:19:27 [debug] 20623#20623: *2 http request line: "GET / HTTP/1.1"
2018/12/15 14:19:27 [debug] 20623#20623: *2 http uri: "/"
2018/12/15 14:19:27 [debug] 20623#20623: *2 http args: ""
2018/12/15 14:19:27 [debug] 20623#20623: *2 http exten: ""
2018/12/15 14:19:27 [debug] 20623#20623: *2 posix_memalign: 000000000120F070:4096 @16
2018/12/15 14:19:27 [debug] 20623#20623: *2 http process request header line
2018/12/15 14:19:27 [debug] 20623#20623: *2 http header: "Host: ssobczak.net"
2018/12/15 14:19:27 [debug] 20623#20623: *2 http header: "Connection: Keep-Alive"
2018/12/15 14:19:27 [debug] 20623#20623: *2 http header: "Accept-Encoding: gzip"
2018/12/15 14:19:27 [debug] 20623#20623: *2 http header: "CF-IPCountry: PL"
2018/12/15 14:19:27 [debug] 20623#20623: *2 http header: "X-Forwarded-For: 89.75.69.70"
2018/12/15 14:19:27 [debug] 20623#20623: *2 http header: "CF-RAY: 48998b975dbf9bd5-AMS"
2018/12/15 14:19:27 [debug] 20623#20623: *2 http header: "X-Forwarded-Proto: https"
2018/12/15 14:19:27 [debug] 20623#20623: *2 http header: "CF-Visitor: {"scheme":"https"}"
2018/12/15 14:19:27 [debug] 20623#20623: *2 http header: "user-agent: curl/7.54.0"
2018/12/15 14:19:27 [debug] 20623#20623: *2 http header: "accept: */*"
2018/12/15 14:19:27 [debug] 20623#20623: *2 http header: "CF-Connecting-IP: 89.75.69.70"
2018/12/15 14:19:27 [debug] 20623#20623: *2 http header done
2018/12/15 14:19:27 [debug] 20623#20623: *2 event timer del: 19: 1544883627407
2018/12/15 14:19:27 [debug] 20623#20623: *2 generic phase: 0
2018/12/15 14:19:27 [debug] 20623#20623: *2 rewrite phase: 1
2018/12/15 14:19:27 [debug] 20623#20623: *2 http set discard body
2018/12/15 14:19:27 [debug] 20623#20623: *2 http script var: "http"
2018/12/15 14:19:27 [debug] 20623#20623: *2 http script copy: "://beta.coralnotes.com"
2018/12/15 14:19:27 [debug] 20623#20623: *2 http script var: "/"
2018/12/15 14:19:27 [debug] 20623#20623: *2 http finalize request: 301, "/?" a:1, c:1
2018/12/15 14:19:27 [debug] 20623#20623: *2 http special response: 301, "/?"
2018/12/15 14:19:27 [debug] 20623#20623: *2 http set discard body
2018/12/15 14:19:27 [debug] 20623#20623: *2 uploadprogress error-tracker error: 301
2018/12/15 14:19:27 [debug] 20623#20623: *2 uploadprogress error-tracker not tracking in this location
2018/12/15 14:19:27 [debug] 20623#20623: *2 xslt filter header
2018/12/15 14:19:27 [debug] 20623#20623: *2 HTTP/1.1 301 Moved Permanently
Server: nginx/1.12.2
Date: Sat, 15 Dec 2018 14:19:27 GMT
Content-Type: text/html
Content-Length: 185
Connection: keep-alive
Location: http://beta.coralnotes.com/

2018/12/15 14:19:27 [debug] 20623#20623: *2 write new buf t:1 f:0 000000000120F4A0, pos 000000000120F4A0, size: 202 file: 0, size: 0
2018/12/15 14:19:27 [debug] 20623#20623: *2 http write filter: l:0 f:0 s:202
2018/12/15 14:19:27 [debug] 20623#20623: *2 http output filter "/?"
2018/12/15 14:19:27 [debug] 20623#20623: *2 http copy filter: "/?"
2018/12/15 14:19:27 [debug] 20623#20623: *2 image filter
2018/12/15 14:19:27 [debug] 20623#20623: *2 xslt filter body
2018/12/15 14:19:27 [debug] 20623#20623: *2 http postpone filter "/?" 000000000120F698
2018/12/15 14:19:27 [debug] 20623#20623: *2 write old buf t:1 f:0 000000000120F4A0, pos 000000000120F4A0, size: 202 file: 0, size: 0
2018/12/15 14:19:27 [debug] 20623#20623: *2 write new buf t:0 f:0 0000000000000000, pos 00000000008D74E0, size: 132 file: 0, size: 0
2018/12/15 14:19:27 [debug] 20623#20623: *2 write new buf t:0 f:0 0000000000000000, pos 00000000008D7280, size: 53 file: 0, size: 0
2018/12/15 14:19:27 [debug] 20623#20623: *2 http write filter: l:1 f:0 s:387
2018/12/15 14:19:27 [debug] 20623#20623: *2 http write filter limit 0
2018/12/15 14:19:27 [debug] 20623#20623: *2 writev: 387 of 387
2018/12/15 14:19:27 [debug] 20623#20623: *2 http write filter 0000000000000000
2018/12/15 14:19:27 [debug] 20623#20623: *2 http copy filter: 0 "/?"
2018/12/15 14:19:27 [debug] 20623#20623: *2 http finalize request: 0, "/?" a:1, c:1
2018/12/15 14:19:27 [debug] 20623#20623: *2 set http keepalive handler
2018/12/15 14:19:27 [debug] 20623#20623: *2 http close request
2018/12/15 14:19:27 [debug] 20623#20623: *2 http log handler
2018/12/15 14:19:27 [debug] 20623#20623: *2 free: 00000000010314A0, unused: 8
2018/12/15 14:19:27 [debug] 20623#20623: *2 free: 000000000120F070, unused: 2330
2018/12/15 14:19:27 [debug] 20623#20623: *2 free: 0000000001212470
2018/12/15 14:19:27 [debug] 20623#20623: *2 hc free: 0000000000000000
2018/12/15 14:19:27 [debug] 20623#20623: *2 hc busy: 0000000000000000 0
2018/12/15 14:19:27 [debug] 20623#20623: *2 tcp_nodelay
2018/12/15 14:19:27 [debug] 20623#20623: *2 reusable connection: 1
2018/12/15 14:19:27 [debug] 20623#20623: *2 event timer add: 19: 65000:1544883632407

==> /var/log/nginx/access.log <==
141.101.104.185 - - [15/Dec/2018:14:19:27 +0000] "GET / HTTP/1.1" 301 185 "-" "curl/7.54.0"

相关内容