我在非标准端口上使用我的应用程序的testing实例,并希望使用nginx将所有传入的http请求redirect到https
这是我的nginxconfiguration:
I tried the above but Cant seem to get it working : please see below ...... include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; server { listen 9000; server_name iossapp1.com; if ($scheme = 'http') { rewrite ^ https://$server_name:9443$request_uri? permanent; } } ssl_certificate /etc/nginx/ssl/server.crt; ssl_certificate_key /etc/nginx/ssl/server.key; server { listen 9443 ssl; server_name iossapp1.com; error_page 497 https://$host:9443$request_uri; location / { proxy_pass http://127.0.0.1:9001; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } }
我已经引用了下面的URL,但似乎有帮助: http : //forum.nginx.org/read.php? 2,155978,213340#msg-213340
添加到这个问题:这个问题仅在我向服务器发送一个表单时出现,下面是一些来自/var/log/nginx/access.log文件的例子:
127.0.0.1 - - [07/Jan/2013:17:29:14 +0800] "GET /admin/logout HTTP/1.1" 302 0 "https://iossapp1.com:9443/admin/iosIndex" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11"
127.0.0.1 - - [07/Jan/2013:17:32:45 +0800] "POST /admin/editStaff HTTP/1.1" 302 0 "https://iossapp1.com:9443/admin/editStaff?staff.id=612" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11" 127.0.0.1 - - [07/Jan/2013:17:32:45 +0800] "GET /admin/staffIndex HTTP/1.1" 304 0 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11"
127.0.0.1 - - [07/Jan/2013:17:35:45 +0800] "POST /admin/authenticate HTTP/1.1" 302 0 "https://iossapp1.com:9443/admin/login" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11" 127.0.0.1 - - [07/Jan/2013:17:35:45 +0800] "GET /admin/masterIndex HTTP/1.1" 304 0 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11"
相比之下,GET URL的行为是这样的: 127.0.0.1 - - [07/Jan/2013:17:36:21 +0800] "GET /admin/masterIndex HTTP/1.1" 200 2324 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11"
我注意到响应代码(302,304)之后的数值在redirect不成功时为0,在其工作的情况下,数值不为零。 这个数字代表什么?
我find了解决办法:
我为proxy_set_header Host $host:$server_port;inputproxy_set_header Host $host:$server_port;
最初是缺less$server_port
资料来源: https : //stackoverflow.com/questions/10168155/nginx-proxy-https-to-http-on-non-standard-port
现在它工作! = d