2013-05-06 173 views
2

我正試着用nginx開始。但我真的不明白這個代碼出了什麼問題。Nginx和子域名

正如你可以看到有兩個域名:

  1. mauromarano.it
  2. dev.mauromarano.it

第一個域承載一個WordPress博客。

##################### 
# mauromarano.it/ # 
#################### 

server { 
    listen 80; 
# listen [::]:80 default_server; 

    root /usr/share/nginx/mauromarano.it/public_html; 
    index index.html index.htm index.php; 

    # Make site accessible from http://localhost/ 
    server_name mauromarano.it www.mauromarano.it; 

    access_log /usr/share/nginx/mauromarano.it/logs/access.log; 
    error_log /usr/share/nginx/mauromarano.it/logs/error.log; 

    location/{ 
     # First attempt to serve request as file, then 
     # as directory, then fall back to displaying a 404. 
     try_files $uri $uri/ /index.html; 
     # Uncomment to enable naxsi on this location 
     # include /etc/nginx/naxsi.rules 
    } 

    location /blog { 
      try_files $uri $uri/ /blog/index.php?$args; 
    } 

    location /doc/ { 
     alias /usr/share/doc/; 
     autoindex on; 
     allow 127.0.0.1; 
     allow ::1; 
     deny all; 
    } 

    location ~ .php$ { 
     fastcgi_pass 127.0.0.1:9000; 
     fastcgi_split_path_info ^(/blog)(/.*)$; 
     fastcgi_param SCRIPT_FILENAME /usr/share/nginx/mauromarano.it/public_html$fastcgi_script_name; 
     fastcgi_index index.php; 
     include fastcgi_params; 
    } 

} 



##################### 
# mauromarano.com # 
#################### 

server { 
    listen 80; 
# listen [::]:80 default_server; 

    root /usr/share/nginx/mauromarano.com/public_html; 
    index index.html index.htm index.php; 

    # Make site accessible from http://localhost/ 
    server_name mauromarano.com www.mauromarano.com; 

    access_log /usr/share/nginx/mauromarano.com/logs/access.log; 
    error_log /usr/share/nginx/mauromarano.com/logs/error.log; 

    location/{ 
     # First attempt to serve request as file, then 
     # as directory, then fall back to displaying a 404. 
     try_files $uri $uri/ /index.html; 
     # Uncomment to enable naxsi on this location 
     # include /etc/nginx/naxsi.rules 
    } 

    location /doc/ { 
     alias /usr/share/doc/; 
     autoindex on; 
     allow 127.0.0.1; 
     allow ::1; 
     deny all; 
    } 

    location ~ .php$ { 
     fastcgi_pass 127.0.0.1:9000; 

     fastcgi_param SCRIPT_FILENAME /usr/share/nginx/mauromarano.com/public_html$fastcgi_script_name; 
     fastcgi_index index.php; 
     include fastcgi_params; 
    } 

} 

##################### 
# dev.mauromarano.it/ # 
#################### 

server { 
    listen 80; 
# listen [::]:80 default_server; 

    root /usr/share/nginx/dev.mauromarano.it/public_html; 
    index index.html index.htm index.php; 

    # Make site accessible from http://localhost/ 
    server_name dev.mauromarano.it www.dev.mauromarano.it; 

    access_log /usr/share/nginx/dev.mauromarano.it/logs/access.log; 
    error_log /usr/share/nginx/dev.mauromarano.it/logs/error.log; 

    location/{ 
     # First attempt to serve request as file, then 
     # as directory, then fall back to displaying a 404. 
     try_files $uri $uri/ /index.html; 
     # Uncomment to enable naxsi on this location 
     # include /etc/nginx/naxsi.rules 
    } 


    location /doc/ { 
     alias /usr/share/doc/; 
     autoindex on; 
     allow 127.0.0.1; 
     allow ::1; 
     deny all; 
    } 

    location ~ .php$ { 
     fastcgi_pass 127.0.0.1:9000; 
     fastcgi_split_path_info ^(/blog)(/.*)$; 
     fastcgi_param SCRIPT_FILENAME /usr/share/nginx/dev.mauromarano.it/public_html$fastcgi_script_name; 
     fastcgi_index index.php; 
     include fastcgi_params; 
    } 

} 

我在哪裏錯了?

我的目標是讓這兩個域名工作。但通過這種方式,子域(dev.mauromarano.it)不起作用。

+0

你有什麼問題?什麼不工作?你的目標是什麼? – kevingessner 2013-05-06 19:11:03

+0

我的目標是讓這兩個域名工作。但通過這種方式,子域(dev.mauromarano.it)不起作用。 – gaggina 2013-05-06 19:19:56

回答

1

以下子句不需要server塊:

listen 80; 
listen [::]:80 default_server; 

這應該解決的子域的問題。除此之外,你錯過了wordpress的重寫規則。他們應該如下:

location/{ 
    try_files $uri $uri/ @wordpress; 
} 
location @wordpress { 
    rewrite ^/(.*)$ /index.php?/$1 last; 
} 

希望這將清除您的問題。有關更多信息將意味着更尖銳的解決方案,但是,請隨時留下您仍然存在的任何錯誤。