我有这个运行良好的配置(我遵循了一些教程来实现这一点):
server {
listen 443 ssl spdy;
server_name mywebsite.com www.mywebsite.com;
# SSL configuration
include snippets/ssl-mywebsite.com.conf;
include snippets/ssl-params.conf;
# Wordpress plugin Rocket-Nginx configuration
include rocket-nginx.conf;
root /var/www/www.mywebsite.com;
index index.php index.html;
set $cache_uri $request_uri;
# POST requests and urls with a query string should always go to PHP
if ($request_method = POST) {
set $cache_uri 'null cache';
}
if ($query_string != "") {
set $cache_uri 'null cache';
}
# Don't cache uris containing the following segments
if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {
set $cache_uri 'null cache';
}
# Don't use the cache for logged in users or recent commenters
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in") {
set $cache_uri 'null cache';
}
location / {
try_files /wp-content/cache/wp-rocket/$http_host/$cache_uri/index.html $uri/ /index.php?$args;
}
location ~ /.well-known {
allow all;
}
location ~ \.(hh|php)$ {
try_files $uri /index.php;
fastcgi_keep_conn on;
fastcgi_pass unix:/var/run/hhvm/hhvm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
include fastcgi_params;
}
location /xmlrpc.php {
deny all;
}
}
server {
listen 80;
server_name mywebsite.com www.mywebsite.com;
location / {
return 301 https://www.mywebsite.com$request_uri;
}
}
但是现在我需要像这样重定向包含 /stats/ 的页面:HTTPS://www.mywebsite.com/STATS/somepage to HTTP://www.mywebsite.com/STATS/somepage.
我想从 ssl 中排除该路径。
我尝试了很多像这样的配置:
server {
listen 443;
location ~* ^/(Stats|stats/.*)$ { # redirect https iframe requests to http server
return 301 http://www.mywebsite.com$request_uri;
}
# ...
}
server {
listen 80;
location / { # the default location redirects to https
return 301 https://www.mywebsite.com$request_uri;
}
location ~* ^/(Stats|stats/.*)$ {} # do not redirect requests for iframe location
}
但我总是收到这个错误:“重定向太多”。
你能告诉我如何实现这个目标吗?
提前致谢