【发布时间】:2021-07-11 11:10:57
【问题描述】:
我在我们网站的根目录中运行一个 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 屏蔽}
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
}
非常感谢您的帮助 - 我已经查看了很多资源并尝试了很多东西但没有成功 - 谢谢。
【问题讨论】:
-
谢谢@Martin,你太棒了——感谢这些——我没有在 Firefox 中检查——只是在 chrome 中测试——在 Firefox 中我得到了 404 ! -- 所以至少事情看起来好多了 --- 似乎我现在在某个地方遇到了链接/路径问题
-
别担心!在 Stack Overflow 上提出新问题的核心原则是首先检查是否还没有提出类似问题,否则您的问题可能会被重复关闭。
-
我更新了问题以反映当前问题,因为 chrome 正在屏蔽 @Martin -- Firefox 显示 /blog 链接的 404 错误
标签: php nginx ubuntu-20.04