使用 nginx - 非常简单的设置和问题,我尝试将所有内容移动到 root 下的博客目录,但 wordpress 301s 从 example.com/blog 回到 example.com。我假设我错过了一些明显的东西,或者wordpress内部有一些东西导致了这种情况,但无法弄清楚
这是我的 nginx 块,当从/服务时有效。
server {
listen 80 ;
server_name $SITE_URL;
server_name _;
# note that these lines are originally from the "location /" block
root /var/www/vhosts/$SITE_URL/httpdocs;
index index.php index.html index.htm;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location / {
# This is cool because no php is touched for static content.
# include the "?" part so non-default permalinks doesn't break when using query string
try_files $uri $uri/ /index.php?$args;
}
location ~* .(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ .(php|phar)(/.*)?$ {
fastcgi_split_path_info ^(.+.(?:php|phar))(/.*)$;
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_intercept_errors on;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
所以我的第一次尝试是将所有内容移动到httpdocs/blog的目录中
并添加
location /blog {
# This is cool because no php is touched for static content.
# include the "?" part so non-default permalinks doesn't break when using query string
try_files $uri $uri/ /blog/index.php?$args;
}
location ~ .(php|phar)(/.*)?$ {
fastcgi_split_path_info ^(/blog.(?:php|phar))(/.*)$;
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_intercept_errors on;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
但没有运气
编辑我刚刚注意到 ip.com/bloggg 会重定向到 ip.com/gg 所以我认为某处有一些规则,但我不知道。.我在nginx中看不到它
编辑2
原来博客中有一个重定向插件重写了/blog...哎 呦
编辑您的 Wordpress 常规设置,根据需要更改这两个 URL。
"网站地址 (URL):输入您希望人们在浏览器中输入的地址以访问您的WordPress网站。[...]"
仔细阅读您必须更改的内容。
https://codex.wordpress.org/Settings_General_Screen
您应该下载该WordPress的sql文件,并将旧URL替换为新url,例如"http://example.com"到"http://example.com/blog"