将url排除在重写之外

时间:2016-02-19 11:46:33

标签: nginx url-rewriting

我已将我的nginx服务器设置为将所有流量从http重定向到https。现在我需要从http访问一个URL。这是我的nginx配置:

server {
    listen 80 default;
    server_name www.example.com example.com;


    location /example_page/ {
            return 301 http://$server_name/example_page/;
    }

    rewrite ^ https://$server_name$request_uri? permanent;
}

但这不会奏效。

1 个答案:

答案 0 :(得分:1)

您可以为整个网站定义规则并排除网址:

server {
  server_name example.com;
  listen 80;
  ...  
  # redirect any http url to https
  location / {
    return 301 https://$server_name$request_uri;
  }

  # but no redirect for this particular location:
  location /example_page/ {
    # usual site rules here (php handler etc)
  }        
}