大网数据广告活动
服务器运维问答

nginx won't redirect http to https

· 52CE 我爱测

I have a nginx docker running, with multiple site-config files. One of those is just a general redirect for all http connnections to https: server { listen 80; server_name *.example.com example.com; return 301 https://$host$reque…

问题原文

原帖链接 · John · CC BY-SA 3.0

I have a nginx docker running, with multiple site-config files.

One of those is just a general redirect for all http connnections to https:

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

all the other site-config files are for my other dockers/services like Nextcloud and Plex.

Whenever I type for example https://plex.example.com into my browser of choice (and even IE), it will show the correct webpage with an ssh-connection.

But, entering http://plex.example.com will just return an empty page and won't redirect me to Plex in this case.

Anyone got an idea?

PS: The default site-config file is empty. But due to the fact, that all the site-configs of the services/dockers are working, I'm guessing, that having the redirect in an extra file won't be the problem.

PPS: Here is an example access-log. The error-log is empty (no new entry for more than 3 months). The log is from accessing my plex-server via https. Accessing anything via http won't create an log entry.

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: The result for 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

Access-log-entry: no entry created

The result for 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

Access-log-entry:

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

P4S The result for 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

已采纳解答

原帖链接 · John · CC BY-SA 3.0

I've found the problem. First, something about my server/setup: its monitoring GUI runs on port 80 by default, never cared to change that. All I did was mapping the external port 80 to the port 84 on my server. With 84 being the port let'sencrypt/nginx is listening.

Now with the recent software update for my router, it chose to ignore the port mapping while accessing the URL from within my LAN. Thus, I was accessing the servers GUI via the http request and got the Access Denied error in the curl.

Got the idea after I tracert'ed the connection to my server.

I'll probably change the port of the server GUI to something else. But for now I'm happy, everything was always working fine

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-11-13)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。