我目前正在为我们公司设置新的服务器,而且我们正在开发很多不同的应用程序,现在我们要在wp.domain.com/app1,wp.domain.com/app2等所有的wordpress应用程序中。
默认不工作的原因是因为我们想为所有的应用程序使用%postname%permalink。
我目前正在通过对每个子文件夹进行重写来进行pipe理,但是我宁愿用一个location块来重写每个子文件夹,所以每当我们上传一个新的应用程序到服务器时,我都不必编辑服务器块。
我们也有可能上传到子目录,例如wp.domain.com/appgroup1/app3,wp.domain.com/appgroup1/app6等。
这是我的wp.domain.comconfiguration:
server { listen 80; root /usr/share/nginx/html/wp; index index.php index.html index.htm; server_name wp.domain.com; location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; } location ~ /(.*)/ { index index.php; try_files $uri $uri/ /$1/index.php?$args; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini # With php5-cgi alone: #fastcgi_pass 127.0.0.1:9000; # With php5-fpm: fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; include fastcgi.conf; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one location ~ /\.ht { deny all; } }
请注意,我们没有使用多站点设置。
这是使用正则expression式块的时候了:
location ~ /(app1|app2|app3|groupapp1(?:/(subapp1|subapp2|subapp3)))/ { try_files $uri $uri/ /$1/index.php$is_args$args; [ ... ] }
从我看到的你可以只留下索引index.php整个服务器{}块,并删除任何/应用程序/位置。 你不需要重写任何东西到index.php。