我在我的主要路线上有一个使用 Laravel 开发的网站,例如 www.example.com/
。我已经使用 Nginx 和 php-fpm 正确配置了它。我的配置如下。
然后我在路由 /blog
(www.example.com/blog/
) 中添加了一个博客,并使用 Nginx alias
配置了它。
现在的问题是 WordPress 中的永久链接不起作用。 Nginx 重定向到 Laravel 的 404 页面。
例如,当用户输入如下 URL:example.com/blog/about
时,Laravel 的 404 页面会显示,这很奇怪。
我该如何解决这个问题?如何配置 Nginx?怎么了?
server {
listen 80;
server_name example.com;
root /usr/share/nginx/html/;
location /blog {
try_files $uri $uri/ /index.php?$args;
alias /usr/share/nginx/blog/;
index index.php index.html index.htm;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx$fastcgi_script_name;
}
}
location / {
root /usr/share/nginx/main_site;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php$is_args$args;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
最佳答案
当位置
与别名路径的末尾匹配时,您不需要使用别名
。请参阅this document .
location/blog
中的 try_files
需要默认为 WordPress 路由器 (/blog/index.php
),而不是 Laravel 路由器(/index.php
)。
尝试:
location /blog {
try_files $uri $uri/ /blog/index.php?$args;
root /usr/share/nginx;
...
location ~ \.php$ {
...
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
关于php - Wordpress 中的永久链接不适用于 Laravel + Nginx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35279010/