简体   繁体   English

Nginx重定向到“ index.html”

[英]Nginx redirecting to “index.html”

I'm using nginx as a reverse proxy in front of a Wordpress instance running on Apache. 我将nginx用作在Apache上运行的Wordpress实例前面的反向代理。 HTTP to HTTPS redirecting is implemented within the nginx config. HTTP到HTTPS重定向是在nginx配置中实现的。

Unfortunately http://example.org is redirecting to https://example.org/index.html instead of https://example.org 不幸的是http://example.org重定向到https://example.org/index.html而不是https://example.org

Here is the basic config: 这是基本配置:

proxy_cache_path  /data/nginx/cache  levels=1:2    keys_zone=STATIC:10m
                                         inactive=24h  max_size=1g;

server {
    listen 80 default deferred;
    server_name example.com staging.example.com;
    rewrite ^/(.+) https://$host/$1 permanent;
}


server {
    listen 443 ssl;

    server_name example.com staging.example.com;
    index index.php;

    root /;

    ssl on;
    ssl_certificate /etc/nginx/ssl/nginx.crt;
    ssl_certificate_key /etc/nginx/ssl/nginx.key;

    location / {
        proxy_pass_header Server;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Scheme $scheme;
        proxy_connect_timeout 10;
        proxy_read_timeout 10;
        proxy_pass http://example-wordpress:80;

        proxy_cache            STATIC;
        proxy_cache_valid      200  1d;
        proxy_cache_use_stale  error timeout invalid_header updating
                               http_500 http_502 http_503 http_504;

    }

    error_page 500 502 503 504 /media/50x.html;
}

Any ideas? 有任何想法吗?

Use return 301 https://$host$request_uri; 使用return 301 https://$host$request_uri; instead of rewrite ^/(.+) https://$host/$1 permanent; 而不是rewrite ^/(.+) https://$host/$1 permanent;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM