我的问题如下:我在Nginx上使用Wordpress和“漂亮的链接”。我还在端口88和1234上运行了2个其他服务,我想创建一个子域名bugs.mydomain和mail.mydomain。我在位置上做了proxypass,但是它只适用于主目录,在域之后的任何东西/落入Wordpress“漂亮的链接”机制。你知道如何解决这个问题吗?我的配置文件如下: 服务器配置:
server {
listen <IP>:80;
root /usr/share/nginx/www/domain;
index index.html index.htm index.php;
server_name domain www.domain;
location / {
try_files $uri $uri/ /index.html;
if ( $host ~ "bugs.domain" ) {
proxy_pass http://domain:88;
}
if ( $host ~ "mail.domain" ) {
proxy_pass http://domain:1234;
}
}
location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
deny all;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
include /home/domain/public_html/nginx.conf;
}
指定域的配置(使用Wordpress):
#First there is many rewrites for the W3TC plugin, like minification, caches etc
if ($host ~* ^www\.(.*))
{
set $host_without_www $1;
rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;
}
#
# unless the request is for a valid file, send to bootstrap
if (!-e $request_filename)
{
rewrite ^(.+)$ /index.php?q=$1 last;
}
现在,当我输入域名:88或域名:1234时,它可以正常运行。当我输入bugs.domain网站加载,但没有CSS或图像工作,因为网址是bugs.domain / somapath,这属于Wordpress引导程序。我没有想法。
答案 0 :(得分:3)
为什么只创建一个带有if的服务器,将服务器分开
server {
listen 80;
server_name bugs.example.com;
proxy_pass http://example.com:88;
}
server {
listen 80;
server_name mail.example.com;
proxy_pass http://example.com:1234;
}
server {
listen 80;
# the rest of your main server
#
}
答案 1 :(得分:1)
所以问题完全不同于我想的。它在这条线上失败了:
try_files $uri $uri/ /index.html;
问题是,文件index.html不存在,我只有index.php。改变它解决了这个问题。