2015-06-09 27 views
0

我成功運行使用NGINX與Meteor一起的Wordpress安裝。我沒有真正的WordPress或PHP經驗,所以這可能是一個簡單的修復。Wordpress未加載共享的NGINX服務器名稱

下面的配置工作:

server_tokens off; 

map $http_upgrade $connection_upgrade { 
    default upgrade; 
    '' close; 
} 

upstream mydomain-production { 
    server localhost:8000; 
} 

# redirect all non-subdomain traffic to https 
server { 
    listen 80; 
    server_name www.mydomain.com mydomain.com; 
    rewrite^https://$host$request_uri? permanent; 
    access_log /var/log/nginx/mydomain.access.log; 
    error_log /var/log/nginx/mydomain.error.log; 
} 

# this non-subdomain serves meteor correctly 
server { 
    listen 443 ssl spdy; 
    server_name www.mydomain.com mydomain.com; 
    access_log /var/log/nginx/mydomain.secure.access.log; 
    error_log /var/log/nginx/mydomain.secure.error.log debug; 

    ssl_certificate #...removed...# ; 
    ssl_certificate_key #...removed...# ; 

    ssl_stapling on; 
    ssl_session_cache shared:SSL:10m; 
    ssl_session_timeout 5m; 

    ssl_prefer_server_ciphers on; 
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 
    ssl_ciphers #...removed...# ; 

    add_header Strict-Transport-Security "max-age=31536000;"; 

    ################################ 
    # additional code will go here # 
    ################################ 

    location/{ 
    proxy_set_header X-Real-IP $remote_addr; 
    proxy_set_header X-Forwarder-For $proxy_add_x_forwarded_for; 
    proxy_set_header Host $http_host; 
    proxy_set_header X-NginX-Proxy true; 

    proxy_pass http://mydomain-production; 
    proxy_redirect off; 

    proxy_http_version 1.1; 
    proxy_set_header Upgrade $http_upgrade; 
    proxy_set_header Connection "upgrade"; 

    if ($uri != '/') { 
     expires 30d; 
    } 
    } 
} 

# this temporary subdomain serves wordpress correctly 
server { 
    listen 80; 
    server_name wordpress.mydomain.com; 
    access_log /var/log/nginx/mydomain.access.log; 
    error_log /var/log/nginx/mydomain.error.log; 
    index index.php index.html index.htm; 
    root /var/www; 

    location/{ 
    try_files $uri $uri/ /index.php?q=$uri&$args; 
    } 

    error_page 404 /404.html; 
    error_page 500 502 503 504 /50x.html; 

    location /50x.html { 
    root /usr/share/nginx/html; 
    } 

    location ~ \.php$ { 
    try_files $uri =404; 

    fastcgi_split_path_info ^(.+\.php)(/.+)$; 
    fastcgi_pass unix:/var/run/php5-fpm.sock; 
    fastcgi_index index.php; 
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    fastcgi_intercept_errors on; 

    include fastcgi_params; 
    } 
} 

所以,因爲我有WordPress的一個臨時子域工作,我希望把它在同一個域中流星工作,包括位置指令來路由某些請求WordPress的,而不是。

我嘗試添加以下到443服務器名稱:

# additional code 

    location /blog { 
    root /var/www; 
    try_files $uri $uri/ /index.php?q=$uri&$args; 
    index index.php index.html index.htm; 
    } 

    location /wp-admin { 
    root /var/www; 
    try_files $uri $uri/ /index.php?q=$uri&$args; 
    index index.php index.html index.htm; 
    } 

    location ~ \.php$ { 
    try_files $uri =404; 

    fastcgi_split_path_info ^(.+\.php)(/.+)$; 
    fastcgi_pass unix:/var/run/php5-fpm.sock; 
    fastcgi_index index.php; 
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    fastcgi_intercept_errors on; 

    include fastcgi_params; 
    } 

這樣做後,我在MYDOMAIN /博客得到一個NGINX 404頁。所以location指令正在成功發送請求到/ var/www而不是Meteor,但由於某種原因它沒有進入Wordpress路由器。我已經鏈接了我的NGINX錯誤調試輸出here

回答

0

這可以通過簡單地將root /var/www;index index.php index.html index.htm;移到位置指令之外來解決。我想知道爲什麼這是必要的,如果任何人可以擺脫這種情況。