同一域下使用 fastcgi 的 Nginx 和多个 wordpress 实例

同一域下使用 fastcgi 的 Nginx 和多个 wordpress 实例

我的网站在 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;
}

添加这个。

相关内容