Nginx wordpress 配置与带有 api 的页面一起导致过多重定向

Nginx wordpress 配置与带有 api 的页面一起导致过多重定向

我在 Nginx 上创建了一些网站,其中包含页面和 API。html 页面的位置是

var/www/mysite/mysite_rest

api 的位置是

var / www / mysite / mysite_rest / api

下一个配置对我来说很好用:

server {
listen 80;
server_name example.com;
#    return 301 https://$host$request_uri;
return 301 https://example.com;
rewrite ^ https://example.com$request_uri? permanent;

client_max_body_size 350M;
}

server {
listen 443 ssl http2;
server_name example.com;

charset UTF-8;

# certs sent to the client in SERVER HELLO are concatenated in 
ssl_certificate
ssl_certificate /etc/ssl/example.crt;
ssl_certificate_key /etc/ssl/example.key;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 30m;
keepalive_timeout 70;
ssl_session_tickets off;

ssl_dhparam /etc/ssl/dhparam.pem;

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers off;

# ssl_stapling on;
ssl_trusted_certificate /etc/ssl/example.crt;
# resolver 8.8.8.8;

# HSTS (ngx_http_headers_module is required) (63072000 seconds)
add_header Strict-Transport-Security "max-age=63072000" always;
# add_header Strict-Transport-Security max-age=31536000 always;
add_header X-Frame-Options DENY;
# add_header Public-Key-Pins 'pin-sha256="base64+info1="; max-age=31536000' 
always;

add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";

##
rewrite ^/(.*)/$ /$1 permanent;
rewrite ^/api/(.*)$ /api/index.php?_url=/$1 last;
rewrite ^/api$ /api/index.php?_url=/ last;

##

location / {
root /var/www/mysite/mysite_rest;
charset utf-8;
index index.php index.html;
}

location /api {
        internal;
        root /var/www/mysite/mysite_rest/api;
        index index.php;
        include /etc/nginx/fastcgi_params;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
 #            fastcgi_pass unix:/var/run/php7.1-fpm.sock;
        fastcgi_pass 127.0.0.1:9000;
         #    fastcgi_param SCRIPT_FILENAME $document_root/index.php;
       fastcgi_param SCRIPT_FILENAME /var/www/mysite/mysite_rest/api/index.php;
   fastcgi_param SCRIPT_NAME index.php;
        fastcgi_param HTTPS on;
#        fastcgi_param HTTP_HTTPS on;
    fastcgi_param REQUEST_SCHEME https;
    fastcgi_param SERVER_PORT 443;

   }         
}

现在我需要在我的网站上安装 wordpress,我下载了它并放在

var/www/mysite/mysite_rest/wp

文件夹,然后在 Nginx conf 中添加以下几行:

location ^~ /wp {
root /var/www/mysite/mysite_rest;
index index.php index.html index.htm;
try_files $uri $uri/ /wp/index.php;

location ~ \.php {
    fastcgi_split_path_info ^(.*\.php)(.*)$;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
    fastcgi_pass 127.0.0.1:9000;
}

}

请求 url: example.com/wp 的结果是 ERR_TOO_MANY_REDIRECTS。但是当我手动请求 example.com/wp/wp-login.php 时它可以正常工作。哪里出了问题?

相关内容