我刚刚用php5-fpm安装了nginx,并且使用一台虚拟主机服务器就可以正常运行。
我刚刚添加了一个wordpress安装(不同的域名)的辅助服务器,当我去它,它总是redirect到第一个虚拟主机已经一直工作。 奇怪的部分是,在错误日志中,我可以看到它从wp-content加载内容失败,但它试图从第一个领域拉…
第一个领域和一个始终如一的作品:
server { listen 80; server_name domain1.com; rewrite ^ https://$server_name$request_uri? permanent; } server { # Change these settings to match your machine listen 443; server_name domain1.com; # Everything below here doesn't need to be changed access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; root /data/www/domain1.com/www/; index index.html index.htm index.php; ssl on; ssl_certificate /data/ssl/domain1.pem; ssl_certificate_key /data/ssl/domain1.key; ssl_session_timeout 5m; if ($host ~* ^www\.(.*)) { set $host_without_www $1; rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent; } location = /favicon.ico { log_not_found off; access_log off; } location = /robots.txt { allow all; log_not_found off; access_log off; } location ~* \.(?:ico|css|js|gif|inc|txt|gz|xml|png|jpe?g) { expires max; add_header Pragma public; add_header Cache-Control "public, must-revalidate, proxy-revalidate"; } location / { try_files $uri $uri/ @rewrites; } location @rewrites { rewrite ^/([^/\.]+)/([^/]+)/([^/]+)/? /index.php?page=$1&id=$2&subpage=$3 last; rewrite ^/([^/\.]+)/([^/]+)/?$ /index.php?page=$1&id=$2 last; rewrite ^/([^/\.]+)/?$ /index.php?page=$1 last; } location /admin { } location /install { } location ~ \.php$ { include /etc/nginx/fastcgi_params; fastcgi_pass unix:/var/run/php5-fpm.sock; # The next two lines should go in your fastcgi_params fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } }
第二个域redirect到第一个域,但资源正在尝试加载:
server { listen 80; server_name domain2.com; # Everything below here doesn't need to be changed access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; root /data/www/domain2.com/public_html/; index index.html index.htm index.php; if ($host ~* ^www\.(.*)) { set $host_without_www $1; rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent; } 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 try_files $uri $uri/ /index.php; } location ~* \.(?:ico|css|js|gif|inc|txt|gz|xml|png|jpe?g) { expires max; add_header Pragma public; add_header Cache-Control "public, must-revalidate, proxy-revalidate"; } location ~ \.php$ { include /etc/nginx/fastcgi_params; fastcgi_pass unix:/var/run/php5-fpm.sock; # The next two lines should go in your fastcgi_params fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } }
错误日志显示尝试从正确的资源,但从错误的领域:
2012/03/11 18:48:45 [error] 29093#0: *26 open() "/data/www/domain1.com/www/wp-content/themes/minimalist/styles/grey.css" failed (2: No such file or directory), client: 60.225.81.244, server: domain1.com, request: "GET /wp-content/themes/minimalist$
这是因为第一台服务器是默认的服务器,它接受任何连接。
我看到你已经试图用if语句设置www.domain2.com 。 www.domain2.com被视为一个不同的服务器..你可以简单地启动另一台服务器:
server { ... server_name www.domain2.com; redirect ^ $scheme://domain2.com$request_uri permanent; }
这应该够了吧。