
我有一個網域,它使用 nginx 網路伺服器為我的網站提供服務,該伺服器使用位置下的選項example.com
指向 nodejs docker 容器 3000 連接埠。proxy pass
/
server {
listen 80 default_server;
server_name example.com www.example.com;
index index.php index.html;
access_log /var/log/nginx/access_example.com.log;
error_log /var/log/nginx/error_example.com.log;
location / {
proxy_pass http://localhost:3000;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
現在我想在下面新增一個wordpress網站,/blog
所以我在伺服器區塊下方新增了這些設定。
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
location /blog {
root /var/www;
try_files $uri $uri/ =404;
}
為什麼我無法存取新安裝的 WordPress,/var/www/blog/
如果我在終端上運行curl http://example.com/blog/license.txt
,沒關係,我可以看到我添加用於測試的license.txt
文件內容,/var/www/blog/
但未index.php
加載。index.html
我認為問題出在線try_files $uri $uri/ =404;
路上,但我沒有發現任何有用的東西。任何幫助將不勝感激
答案1
您可能知道,Wordpress 使用前端控制器架構 - 即執行任何 PHP 腳本的入口點是 $WORDPRESS_ROOT/index.php。您需要告訴 nginx 相應地路由請求:
try_files $uri $uri/ /blog/index.php?$args;
請注意,對大多數靜態內容的請求將由前 2 個值之一處理。沒有 404 個處理程序,因為 Wordpress 需要自己處理該場景。
但index.php未載入
嗯,對所發生的事情沒有一個非常有意義的描述 - 即您是否明確表示 ..../index.php 還是只是 .../ ?你得到什麼回應?你的日誌裡有什麼?
PHP(以及大多數 fcgi 處理程序)需要相當多的配置,這些配置通常包含在配置中的其他位置。在 Ubuntu 上,如果從儲存庫安裝,我預計這已經就位,但建議對此進行測試。我還建議在進行上述前端控制器修改之前解決這個問題,因為這會使事情變得更加複雜。使用簡單的“hello world”PHP 腳本。