我阅读并遵循this question以配置nginx以强制一个页面的SSL(对于XenForo为admin.php),并且它对一些站点管理员工作得很好但不适合我自己.我想知道是否有人对如何改进此配置有任何建议:
...
ssl_certificate example.net.crt;
ssl_certificate_key example.key;
server {
listen 80 default;
listen 443 ssl;
server_name www.example.net example.net;
access_log /srv/www/example.net/logs/access.log;
error_log /srv/www/example.net/logs/error.log;
root /srv/www/example.net/public_html;
location / {
if ( $scheme = https ){
return 301 http://example.net$request_uri;
}
try_files $uri $uri/ /index.php?$uri&$args;
index index.php index.html;
}
location ^~ /admin.php {
if ( $scheme = http ) {
return 301 https://example.net$request_uri;
}
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS on;
}
location ~ \.php${
try_files $uri =404;
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
...
似乎位置^/ admin.php块中的额外信息是不必要的,有没有人知道避免重复代码的简单方法?没有它它会跳过php块并返回php文件.
目前,当我导航到admin.php时,它在Firefox中正确应用https.在Chrome中,它会下载admin.php页面.返回到Firefox中的非https网站时,它无法正确返回http,但保留为SSL.就像我之前说的那样,这只发生在我身上,其他管理员可以毫无问题地来回走动.
这是我能解决的问题吗?有没有人知道我可以减少配置中的重复配置选项的任何方法?提前致谢!
编辑:清除缓存/ cookie似乎工作.这是进行http / https重定向的正确方法吗?当我走的时候,我有点做了.
最佳答案
ways I could reduce duplicate configuration options in the configuration
可能使用@ -named位置.见doc.