I would like to rewrite 'https://www.example.com' and 'https://example.com' to 'http://www.example.com' or 'http://example.com respectively'. I only want to write that specific part of the site not any subfolders or php related pages. How do I do thi开发者_如何学Pythons?
I use it in the other direction (not tested in this direction but should work).
if ( $scheme = https )
{
rewrite ^ http://$host$uri;
}
EDIT: limit to a location and end don't try to rewrite more:
location / {
if ( $scheme = https )
{
rewrite ^ http://$host$uri last;
}
}
I've used something similar to the following, which avoid's IfIsEvil and uses return instead of rewrite
. However it fails DRY, which bothers me.. Suggestions welcome.
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;
}
}
See also
- nginx http location docs
- related nginx https to http answer
精彩评论