php - NginX Ubuntu 20.04 PHP 7.4 上的 wordpress /blog 文件出现 404 错误
问题描述
我在我们网站的根目录中运行一个 VueJS 系统,驱动同一服务器上的 Django API。
example.com 是 beta 测试版。
我想将 wordpress 加载到子文件夹example.com/blog
我正在运行 Nginx [没有 Apache - 并且未安装 Apache]。
已安装 PHP 和 MySQL 并编辑我们的服务器块。请参阅下面的代码。
我尝试在 /blog 中访问的任何文件都出现 404 错误,例如
https://example.com/blog/readme.html
https://example.com/blog/test.php
https://example.com/blog/index.php
https://example.com/blog/wp-admin/install.php
这是我们的服务器块代码 {IP masked out}
server {
server_name example.com www.example.com 128.199.###.###;
root /var/www/html/vue/example/dist;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
alias /home/example/src;
}
location / {
try_files $uri $uri/ /index.html /index.php;
}
location ^~ /rest-auth/ {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
location ^~ /api/ {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
location ~ /\.ht {
deny all;
}
location ^~ /admin {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
location ^~ /blog {
alias /var/www/html;
index index.php index.html index.htm;
try_files $uri =404;
}
# For security reasons, set php settings at root level.
# This prevents root level php files from showing as plain text.
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
error_log /var/log/nginx/example-error.log;
access_log /var/log/nginx/example-access.log;
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = www.example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name example.com www.example.com 128.199.###.###;
return 404; # managed by Certbot
}
非常感谢您的帮助-我查看了很多资源并尝试了很多东西但没有成功-谢谢。
解决方案
chrome 下载问题掩盖了代码中一个简单的错误路径!Firefox 显示了一个简单的 404,它很容易调试!
最终的解决方案是为博客添加这个位置:
location /blog {
alias /var/www/html/blog;
try_files $uri $uri/ @blog;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
}
location @blog {
rewrite /blog/(.*)$ /blog/index.php?/$1 last;
}
推荐阅读
- java - 应用程序属性“server.servlet.session.timeout”在 Spring Boot 项目中不起作用
- swift - TableViewCell 笔尖错误:已加载笔尖但未设置视图出口
- llvm - llvm 在循环中通过添加函数调用(通过感应变量进行参数)
- html - 防止鼠标悬停在孩子上时父母调整大小
- ios - 错误 ITMS-90171:“无效的捆绑结构不允许使用二进制文件 MyApp.app/libswiftRemoteMirror.dylib
- c# - 如何检查输入的十进制值是否大于十进制列表
- android - 在发布模式下启用 Proguard 后 Firebase 应用内消息崩溃
- sql-server - 如何重命名 SQL Server 2016 数据库,包括物理文件,即 .mdf 和 .log 文件
- javascript - 比较 JavaScript 中对象数组的两个参数
- javascript - 我怎样才能承诺一个 AJAX 请求 onreadystatechange?