![Nginx 和同一網域下具有 fastcgi 的多個 WordPress 實例](https://rvso.com/image/515679/Nginx%20%E5%92%8C%E5%90%8C%E4%B8%80%E7%B6%B2%E5%9F%9F%E4%B8%8B%E5%85%B7%E6%9C%89%20fastcgi%20%E7%9A%84%E5%A4%9A%E5%80%8B%20WordPress%20%E5%AF%A6%E4%BE%8B.png)
我的網站在 Apache 上運行。路徑 /tr/ 和 /eng/ 下存在兩個 wordpress 實例。我想將設定移至 nginx,但無法使其正常工作。
我的設定包括 nging 0.7.66、php 5.3.2 和 php-fpm。 /tr/ 和 /eng/ 是兩個單獨的 wordpress 實例,分別位於 /home/istci/webapps/wordpress_tr 和 /home/istci/webapps/wordpress 下。
下面是 nginx.conf 中的伺服器部分,僅包含 tr 的配置,但也無法使其運作。
server {
listen 80;
server_name www.example.com;
charset utf-8;
location ~ ^/$ {
rewrite ^(.+)$ http://www.example.com/tr/ permanent;
}
location ~ /tr/.*php$ {
fastcgi_pass unix:/home/istci/var/run/wptr.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/istci/webapps/wordpress_tr$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
}
location /tr/ {
root /home/istci/webapps/wordpress_tr/;
index index.php index.html index.htm;
if (!-e $request_filename) {
rewrite ^(.+)$ /tr/index.php?q=$1 last;
break;
}
if (-f $request_filename) {
expires 30d;
break;
}
}
}
php-fpm 監聽 unix:/home/istci/var/run/wptr.sock。在調試模式下運行它顯示沒有活動處理程序,這意味著 nginx 沒有與 unix 套接字建立連接。
nginx訪問日誌:
127.0.0.1 - - [09/Jun/2010:03:45:11 -0500] "GET /tr/ HTTP/1.0" 404 20 "-" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.4) Gecko/20100527 Firefox/3.6.4"
Nginx 調試日誌:
2010/06/09 03:38:53 [notice] 6922#0: built by gcc 4.1.2 20080704 (Red Hat 4.1.2-48)
2010/06/09 03:38:53 [notice] 6922#0: OS: Linux 2.6.18-164.9.1.el5PAE
2010/06/09 03:38:53 [notice] 6922#0: getrlimit(RLIMIT_NOFILE): 4096:4096
2010/06/09 03:38:53 [notice] 6923#0: start worker processes
2010/06/09 03:38:53 [notice] 6923#0: start worker process 6924
2010/06/09 03:38:53 [notice] 6923#0: start worker process 6925
2010/06/09 03:39:01 [notice] 6925#0: *1 "^(.+)$" matches "/tr/", client: 127.0.0.1, server: www.example.com, request: "GET /tr/ HTTP/1.0", host: "www.example.com"
2010/06/09 03:39:01 [notice] 6925#0: *1 rewritten data: "/tr/index.php", args: "q=/tr/", client: 127.0.0.1, server: www.example.com, request: "GET /tr/ HTTP/1.0", host: "www.example.com"
關於我的配置有什麼問題的任何線索嗎?謝謝。
答案1
閱讀try_files
location /tr {
try_files $uri $uri/ /tr/index.php;
}
location /eng {
try_files $uri $uri/ /eng/index.php;
}
添加這個。