Php 将单页https重写为http Nginx
我想重写一下https://www.example.com“还有”https://example.com“到”http://www.example.com“或者”http://example.com 分别”。我只想写该网站的特定部分,而不是任何子文件夹或php相关页面。如何做到这一点?我在另一个方向上使用它(没有在这个方向上测试,但应该可以工作) 编辑:限制到某个位置并结束不要尝试重写更多:Php 将单页https重写为http Nginx,php,ssl,joomla,nginx,rewrite,Php,Ssl,Joomla,Nginx,Rewrite,我想重写一下https://www.example.com“还有”https://example.com“到”http://www.example.com“或者”http://example.com 分别”。我只想写该网站的特定部分,而不是任何子文件夹或php相关页面。如何做到这一点?我在另一个方向上使用它(没有在这个方向上测试,但应该可以工作) 编辑:限制到某个位置并结束不要尝试重写更多: location / { if ( $scheme = https ) { rewrit
location / {
if ( $scheme = https )
{
rewrite ^ http://$host$uri last;
}
}
我使用了类似于以下内容的东西,它避免使用,而不是
rewrite
。但是它失败了,这让我很烦恼。。欢迎提出建议
server {
listen 80;
server_name .example.com;
index index.html index.htm index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock ;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
server {
listen 443 ssl;
server_name .example.com;
ssl_certificate /etc/ssl/certs/example.com.cert;
ssl_certificate_key /etc/ssl/private/example.com.key;
index index.html index.htm index.php;
# Rewrite only / to http
location = / {
return 301 http://$server_name$request_uri;
}
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock ;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
另见
位置上下文中可以在内部执行的唯一100%安全的操作是:返回…;
重写…最后;
”。这是第二种情况,你有更好的解决方案吗?
server {
listen 80;
server_name .example.com;
index index.html index.htm index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock ;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
server {
listen 443 ssl;
server_name .example.com;
ssl_certificate /etc/ssl/certs/example.com.cert;
ssl_certificate_key /etc/ssl/private/example.com.key;
index index.html index.htm index.php;
# Rewrite only / to http
location = / {
return 301 http://$server_name$request_uri;
}
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock ;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}