2017-04-18 119 views
2

我試圖在Nginx的三個不同目錄中託管三個獨立的WordPress站點。經過數小時的研究,我完全無法找到允許我訪問網站上的/wp-admin和各種網頁的配置。Nginx - 不同子目錄中的多個WordPress網站 -/wp-admin重定向循環

這裏是我的時刻:

server { 
     listen 80; 
     listen [::]:80 ipv6only=on; 

     root /var/www; 
     server_name my.ip.add.ress; 

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

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

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

     if (!-e $request_filename) { 
      rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last; 
      rewrite ^/[_0-9a-zA-Z-]+.*(/wp-admin/.*\.php)$ $1 last; 
      rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last; 
     } 

     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; 
       include fastcgi_params; 

       fastcgi_cache moodle; 
       fastcgi_cache_valid 200 60m; 

       fastcgi_read_timeout 3600; 
     } 

     # Cache static content 
     location ~* .(jpg|jpeg|png|gif|ico|css|js)$ { 
       expires 365d; 
     } 
} 

當我試圖訪問/可溼性粉劑管理員,我的瀏覽器被卡在重定向循環。使用rewrite_log不會輸出。

回答

0

在你的問題,你有這樣的:

root /var/www; 
... 
location /wp1 { 
    root /var/www/wp1; 
    ... 
} 

/wp1/foo路徑名解析爲/var/www/wp1/wp1/foo。請注意,您已經在路徑名中添加了第二個術語/wp1/

裏面location /wp1根不變。您不需要在每個位置中指定root,因爲它仍然是root /var/www;,無論如何它都將從外部塊繼承。

刪除線:

root /var/www/wp1; 
root /var/www/wp2; 
root /var/www/wp3; 

更多見this document

相關問題