在使用 nginx 的子目錄中安裝 WordPress

正在檢視 2 個帖子:1-2 (共 2 個帖子)
  • 作者
    帖子
  • 詩語
    管理員
    • 文章數量: 5,935
    @feibisi
    樓主

    所以我最近遇到了這個問題,我在主域中有一個 WordPress 站點,而另一個 WordPress 安裝在主安裝中的子目錄/資料夾中。主站點工作正常,管理面板等,但當你試圖改變永久連結,一切都有一個 404 錯誤。

    我注意到所有的請求都被路由回主域 (沒有額外的資料夾),所以我猜想它可能與 nginx 有關,最有可能是這樣的:

    location / {
    # This is cool because no php is touched for static content
    try_files $uri $uri/ /index.php?$query_string;
    }

    這打破了資料夾內的重寫並將所有內容傳送到主站點,以使其工作,我不得不為子目錄新增幾個位置指令 – 現在所有不同型別的固定連結配置都可以工作。

    這讓網站工作得很好:

    location /subinstall {
    root /home/maindomain.com/public_html/subinstall;
    index index.php index.html index.htm;
    try_files $uri $uri/ @wp;
    }
    
    location @wp {
    rewrite ^/subinstall(.*) /subinstall/index.php?q=$1;
    }

    使用 /subinstall 作為第二個 WordPress 安裝的子資料夾的名稱。

     

    詩語
    管理員
    • 文章數量: 5,935
    @feibisi
    樓主

    也就是說比如要建一個 forum 的子目錄,那麼可以偽靜態裡面加一段:

    location /forum {
         try_files $uri $uri/ /forum/index.php?$args;
    }

    這樣就行了。

正在檢視 2 個帖子:1-2 (共 2 個帖子)
  • 哎呀,回覆話題必需登入。

話題資訊