我有一个启用了ssl的Nginx服务器.
目前我已为所有目录启用了https.
如何在www.example.com/shop/*目录中启用ssl并禁用其他?
这是我的conf文件:
# Redirect everything to the main site.
server {
server_name *.example.com;
listen 80;
ssl on;
ssl_certificate /opt/Nginx/conf/server.crt;
ssl_certificate_key /opt/Nginx/conf/server.key;
keepalive_timeout 70;
access_log /home/example/Nginx_logs/access.log ;
error_log /home/example/Nginx_logs/error.log ;
root /home/example/public_html/example.com;
location ~ \.PHP${
try_files $uri $uri/ /index.PHP?q=$uri&$args;
root /home/example/public_html/example.com/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.PHP;
include /opt/Nginx/conf/fastcgi_params;
#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME /home/example/public_html/example.com$fastcgi_script_name;
index index.PHP index.html index.htm;
}
if ($http_host != "example.com") {
rewrite ^ http://example.com$request_uri permanent;
}
include global/restrictions.conf;
# Additional rules go here.
#Only include one of the files below.
include global/wordpress.conf;
# include global/wordpress-ms-subdir.conf;
# include global/wordpress-ms-subdomain.conf;
}
tnanks,
d
解决方法:
在Nginx中很容易实现.它涉及两个步骤.
>只有访问yourdomain.com/shop时才会使用端口443.所有其他请求将被重定向到端口80(HTTP)
> 80端口将检查yourdomain.com/shop.如果找到,它将被重定向到端口443(HTTPS).
以下是如何完成的快速概述……
server {
listen 443;
server_name yourdomain.com;
# directives for SSL certificates
# root, index, error_log, access_log directives
location /shop {
# directives to handle what's inside /shop, for example
# try_files $uri $uri/ /index.PHP;
}
location ~ \.PHP${
# directives to handle PHP files
}
# leave everything else to port 80
location / {
rewrite ^ http://$host$request_uri permanent;
}
}
server {
listen 80;
server_name yourdomain.com;
# root, index, error_log, access_log directives
# redirect yourdomain.com/shop to port 443
# Please put this before location / block as
# Nginx stops after seeing the first match
location /shop {
rewrite ^ https://$host$request_uri permanent;
}
location / {
# directives to handle what's inside /, for example
# try_files $uri $uri/ /index.PHP;
}
location ~ \.PHP${
# directives to handle PHP files
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。