Nginx使用相同的域和不同的子目录托管多个php站点

时间:2014-06-22 13:34:52

标签: php wordpress nginx

我想在一个网站mysite.example.com下使用Nginx拥有2个php子目录。这两个php目录使用相同的域名mysite.example.com但在文件系统中使用不同的位置。

site1: mysite.example.com/wordpress (/var/www/wordpress)

site2: mysite.example.com/new_site (var/www/new__php_site)

我的以下配置适用于mysite.example.com的wordpress网站,但如何使mysite.example.com/wordpress正常工作?

# Upstream to abstract backend connection(s) for php
upstream php {
        server unix:/tmp/php-cgi.socket;
        server 127.0.0.1:9000;
}

server {
        ## Your website name goes here.
        server_name mysite.example.com;
        ## Your only path reference.
        root /var/www/wordpress;
        ## This should be in your http block and if it is, it's not needed here.
        index index.php;

        location = /favicon.ico {
                log_not_found off;
                access_log off;
        }

        location = /robots.txt {
                allow all;
                log_not_found off;
                access_log off;
        }

        location / {
                # This is cool because no php is touched for static content. 
                # include the "?$args" part so non-default permalinks doesn't break when using query string
                try_files $uri $uri/ /index.php?$args;
        }

        location ~ \.php$ {
                #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
                include fastcgi.conf;
                fastcgi_intercept_errors on;
                fastcgi_pass php;
        }

        location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
                expires max;
                log_not_found off;
        }
}

还有如何让mysite.example.com/new-site工作?下面的重写适用于多个wordpress网站,但多个一般的php网站怎么样?

# Rewrite rules for WordPress Multi-site.
if (!-e $request_filename) {
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last;
rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;
}

0 个答案:

没有答案