【发布时间】:2017-07-09 23:18:08
【问题描述】:
我是这样配置Nginx的:
#/etc/nginx/conf.d/default.conf
server {
listen 8081 default_server;
listen [::]:8081 default_server ipv6only=on;
server_name localhost;
listen 443 ssl;
location /site/ {
proxy_pass http://127.0.0.1:8084/;
}
# 404 occured
#location /site/secure/ {
# proxy_redirect http://localhost:8081/site/secure/ https://localhost/site/secure/;
#}
location / {
root /srv;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
ssl_certificate /etc/nginx/ssl/nginx.crt;
ssl_certificate_key /etc/nginx/ssl/nginx.key;
}
我已启用 https。 我有几个网址:
http://127.0.0.1:8081/site/secure/
http://127.0.0.1:8081/sute/path1/...
http://127.0.0.1:8081/sute/path2/...
我只想将http://127.0.0.1:8081/site/secure/* 请求重定向到https://127.0.0.1/site/secure/*,这样用户就不能通过简单的http 使用这个url。
但是当我使用这个重定向运行 Nginx 时:
location /site/secure/ {
proxy_redirect http://localhost:8081/site/secure/ https://localhost/site/secure/;
}
我收到 404 响应:
<html>
<head>
<title>404 Not Found</title>
</head>
<body bgcolor="white">
<center>
<h1>404 Not Found</h1>
</center>
<hr>
<center>nginx/1.4.6 (Ubuntu)</center>
</body>
</html>
如何配置 nginx 以正确的方式将某些请求重定向到 https?
【问题讨论】: