Nginx:将所有内容重定向到http://example.com

时间:2015-01-23 05:03:01

标签: python django nginx flask

我想了解将所有内容重定向到http://example.com/的正确Nginx配置...即:

  1. https://example.com/
  2. https://www.example.com/
  3. http://www.example.com/
  4. 需要自动重定向到http://example.com/。我该如何配置?

1 个答案:

答案 0 :(得分:2)

您可以这样做:

server {
    listen 80;
    server_name www.example.com;
    return 301 $scheme://example.com$request_uri;
}
server {
    listen   80;
    server_name example.com;
    <your other nginx settings>
}
server {
    listen 443;
    server_name www.example.com;
    return 301 $scheme://example.com$request_uri;
}
server {
    listen 443;
    server_name example.com;
    return 301 http://example.com$request_uri;
}