Apache 仅针对nginx上的特定url使用https重定向
我正在尝试让https与一些URL一起工作。但https似乎无处不在。具体来说,我在Nginx上创建了2个vhost。第一个虚拟主机的端口为80,另一个虚拟主机的端口为443,包含SSL。现在,我的site.i.e domain.com同时适用于http和https,这不是我想要的。我希望https在我用Nginx vhost中的规则指定的一些URL上工作 主要问题是,当我尝试首先使用http获取我的主站点时,然后当我转到包含https“secure_area”的url时,它工作正常。然而,每当我在我的站点中的其他地方进行此操作时,https就会继续在所有其他URL上运行 这是我的443 vhost配置:Apache 仅针对nginx上的特定url使用https重定向,apache,ssl,nginx,https,http-redirect,Apache,Ssl,Nginx,Https,Http Redirect,我正在尝试让https与一些URL一起工作。但https似乎无处不在。具体来说,我在Nginx上创建了2个vhost。第一个虚拟主机的端口为80,另一个虚拟主机的端口为443,包含SSL。现在,我的site.i.e domain.com同时适用于http和https,这不是我想要的。我希望https在我用Nginx vhost中的规则指定的一些URL上工作 主要问题是,当我尝试首先使用http获取我的主站点时,然后当我转到包含https“secure_area”的url时,它工作正常。然而,每当
server {
listen 80 default_server;
server_name mydomain.com;
return 301 http://www.mydomain.com;
}
server {
listen 80;
server_name www.mydomain.com;
root /vars/www/public_html/;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8080;
}
location ~ /\.ht {
deny all;
}
location /secure_area/ {
rewrite ^ https://$http_host$request_uri? permanent;
}
}
ssl_会话_缓存共享:ssl:5m;
添加_头严格传输安全“最大年龄=31536000;包括子域”
这是我的80 vhost配置:
server {
listen 80 default_server;
server_name mydomain.com;
return 301 http://www.mydomain.com;
}
server {
listen 80;
server_name www.mydomain.com;
root /vars/www/public_html/;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8080;
}
location ~ /\.ht {
deny all;
}
location /secure_area/ {
rewrite ^ https://$http_host$request_uri? permanent;
}
}
如果没有人注意到,Nginx在前端Apache中充当反向proexy
现在有人知道如何只在一些URL上强制使用https了吗?在我的例子中,安全区域和所有其他URL上强制使用http
谢谢如果访问了任何其他URL,您可以告诉SSL服务器重定向回http
server {
listen 80;
server_name example.com;
# normal http settings
location /secure_area/ {
return 301 https://$http_host$request_uri$is_args$query_string;
}
}
server {
listen 443 ssl spdy;
server_name example.com;
# ssl settings;
location /secure_area/ {
#serve secure area content
}
location / {
return 301 http://$http_host$request_uri$is_args$query_string;
}
}
感谢@Mohammad的密码。我将尝试一下,看看它是否有效。不幸的是,在尝试了最后两个小时后,代码没有工作。这可能只适用于通配符SSL,不是吗?您是否为第一台服务器设置了
位置/
?正常的http服务器是的,我这样做了,但没有工作。是否必须将服务器块分开或放在同一块中,这有关系吗?您可以在我在代码中注释的位置添加配置,例如#ssl设置
,#服务安全区域
和#正常http设置