nginx 不会将 http 重定向到 https

nginx 不会将 http 重定向到 https

我有一个正在运行的 nginx docker,多种的 site-config文件。

其中之一只是将所有 http 连接重定向到 https:

server {
listen 80;
server_name *.example.com example.com;
return 301 https://$host$request_uri;
}

所有其他site-config文件均用于我的其他 docker/服务,例如 Nextcloud 和 Plex。

每当我输入例如https://plex.example.com进入我选择的浏览器(甚至是 IE),它将显示具有 ssh 连接的正确网页。

但是,进入http://plex.example.com在这种情况下,只会返回一个空白页,并且不会将我重定向到 Plex。

有人有主意吗?

附言: 默认site-config文件是空的。但由于所有site-configs服务/docker 都在运行,我猜在额外的文件中进行重定向不会有问题。

备注: 以下是访问日志示例。错误日志为空(超过 3 个月没有新条目)。该日志来自通过 https 访问我的 plex 服务器。通过 http 访问任何内容都不会创建日志条目。

192.168.0.2 - - [13/Nov/2017:21:53:02 +0100] "GET / HTTP/1.1" 401 157 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko"
192.168.0.2 - - [13/Nov/2017:21:53:02 +0100] "GET /web/index.html HTTP/1.1" 200 1650 "https://plex.example.com/" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko"
192.168.0.2 - - [13/Nov/2017:21:53:02 +0100] "GET /web/main.8883144fb7acc2430ef50eda6c1a41c8.css HTTP/1.1" 200 764765 "https://plex.example.com/web/index.html" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko"
192.168.0.2 - - [13/Nov/2017:21:53:02 +0100] "GET /web/main.v3.3a6aa4986f36a5810792d74118deda14.css HTTP/1.1" 200 214735 "https://plex.example.com/web/index.html" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko"
192.168.0.2 - - [13/Nov/2017:21:53:02 +0100] "GET /web/js/vendors-1-d55a6a600958df7159e4-plex-3.20.7-d87fe16.js HTTP/1.1" 200 1148751 "https://plex.example.com/web/index.html" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko"
192.168.0.2 - - [13/Nov/2017:21:53:02 +0100] "GET /web/js/main-0-2a819e76950d4ad197a8-plex-3.20.7-d87fe16.js HTTP/1.1" 200 3259450 "https://plex.example.com/web/index.html" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko"
192.168.0.2 - - [13/Nov/2017:21:53:02 +0100] "GET /web/common/img/backgrounds/preset-dark.5b95c8c24aab87067b69bca7ae11759a.png HTTP/1.1" 200 40582 "https://plex.example.com/web/index.html" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko"
192.168.0.2 - - [13/Nov/2017:21:53:02 +0100] "GET /web/translations/de.json HTTP/1.1" 200 128137 "https://plex.example.com/web/index.html" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko"
192.168.0.2 - - [13/Nov/2017:21:53:02 +0100] "GET /web/common/img/backgrounds/noise.0e9cf16a17adb19690cd31312cdaa809.png HTTP/1.1" 200 94668 "https://plex.example.com/web/index.html" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko"
192.168.0.2 - - [13/Nov/2017:21:53:03 +0100] "GET /web/favicon.ico HTTP/1.1" 200 5430 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; Trident/7.0; rv:11.0) like Gecko"
192.168.0.2 - - [13/Nov/2017:21:53:03 +0100] "GET /?X-Plex-Product=Plex%20Web&X-Plex-Version=3.20.7&X-Plex-Client-Identifier=yi606rcck7j3x9lx3wafhzgx&X-Plex-Platform=Internet%20Explorer&X-Plex-Platform-Version=11.0&X-Plex-Device=Windows&X-Plex-Device-Name=Plex%20Web%20%28Internet%20Explorer%29&X-Plex-Device-Screen-Resolution=1149x738%2C2560x1440 HTTP/1.1" 401 157 "https://plex.example.com/web/index.html" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko"
192.168.0.2 - - [13/Nov/2017:21:53:03 +0100] "GET /identity?X-Plex-Product=Plex%20Web&X-Plex-Version=3.20.7&X-Plex-Client-Identifier=yi606rcck7j3x9lx3wafhzgx&X-Plex-Platform=Internet%20Explorer&X-Plex-Platform-Version=11.0&X-Plex-Device=Windows&X-Plex-Device-Name=Plex%20Web%20%28Internet%20Explorer%29&X-Plex-Device-Screen-Resolution=1149x738%2C2560x1440 HTTP/1.1" 200 160 "https://plex.example.com/web/index.html" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko"
192.168.0.2 - - [13/Nov/2017:21:53:06 +0100] "POST /index.php/heartbeat HTTP/1.1" 200 31 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"

P3S: 结果为curl -i http://cloud.example.com/

HTTP/1.1 401 Unauthorized
WWW-Authenticate: Basic realm='unRAID SMU'
Server: emhttp
Connection: close
Content-Type: text/plain
Content-Length: 16

401 Unauthorized

访问日志条目:未创建条目

结果为curl -i https://cloud.example.com/

HTTP/1.1 302 Found
Server: nginx/1.12.2
Date: Mon, 13 Nov 2017 21:20:39 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
X-Powered-By: PHP/7.1.9
Set-Cookie: oc367h1rrnkw=6033cj2p99saalb4csog6k47p5; path=/; HttpOnly
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Set-Cookie: oc_sessionPassphrase=SECRETPASSPHRASE; path=/; secure; HttpOnly
Content-Security-Policy: default-src 'self'; script-src 'self' 'unsafe-eval' 'nonce-cHlJeHJhUFhzZWJmdDdwSWVkVisrYUFPMGVVd1p1eDJXSW44TkhESE9HND06eVZ0dzFPU1p3N1d1OE1BdEhib3cxdk1obWFwMFBvSThhc0dVZnlTZ0NUMD0='; style-src 'self' 'unsafe-inline'; frame-src *; img-src * data: blob:; font-src 'self' data:; media-src *; connect-src *; object-src 'none'; base-uri 'self';
X-Frame-Options: SAMEORIGIN
Set-Cookie: __Host-nc_sameSiteCookielax=true; path=/; httponly;secure; expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=lax
Set-Cookie: __Host-nc_sameSiteCookiestrict=true; path=/; httponly;secure; expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=strict
Location: https://cloud.example.com/index.php/login
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
X-Robots-Tag: none
X-Download-Options: noopen
X-Permitted-Cross-Domain-Policies: none
Strict-Transport-Security: max-age=63072000; includeSubdomains
Front-End-Https: on

访问日志条目:

192.168.0.2 - - [13/Nov/2017:22:24:11 +0100] "GET / HTTP/1.1" 302 5 "-" "curl/7.47.0"

P4S 结果为netstat -natup | grep nginx

tcp        0      0 0.0.0.0:80              0.0.0.0:*             LISTEN      305/nginx.conf
tcp        0      0 0.0.0.0:443             0.0.0.0:*             LISTEN      305/nginx.conf
tcp        0      0 172.17.0.5:443          192.168.0.2:56973     ESTABLISHED 336/nginx: worker p
tcp        0      0 172.17.0.5:443          192.168.0.2:56977     ESTABLISHED 336/nginx: worker p
tcp        0      0 172.17.0.5:443          192.168.0.2:56981     ESTABLISHED 336/nginx: worker p
tcp        0      0 172.17.0.5:443          192.168.0.2:56722     ESTABLISHED 336/nginx: worker p
tcp        0      0 172.17.0.5:443          192.168.0.2:56976     ESTABLISHED 336/nginx: worker p
tcp        0      0 172.17.0.5:443          192.168.0.2:56980     ESTABLISHED 336/nginx: worker p
tcp        0      0 172.17.0.5:443          192.168.0.2:56971     ESTABLISHED 336/nginx: worker p
tcp        0      0 172.17.0.5:443          192.168.0.2:56966     ESTABLISHED 335/nginx: worker p

答案1

我找到了问题所在。首先,关于我的服务器/设置:它的监控 GUI 默认在端口 80 上运行,从未想过要更改这一点。我所做的只是将外部端口 80 映射到我服务器上的端口 84。84 是 let'sencrypt/nginx 正在监听的端口。

现在,我的路由器最近进行了软件更新,它选择在从我的 LAN 内访问 URL 时忽略端口映射。因此,我通过 http 请求访问服务器 GUI,并Access Denied在 curl 中收到错误。

在我对与我的服务器的连接进行 tracert 之后,我就有了这个想法。

我可能会将服务器 GUI 的端口更改为其他端口。但目前我很高兴,一切都运行良好

相关内容