2013-05-06 2 views
2

Я пытаюсь начать работу с nginx. Но я не могу понять, что происходит с этим кодом.Nginx и поддомены

Как вы можете видеть, что есть 2 доменов:

  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

+0

Моя цель: работать с двумя доменами. Но в этом случае субдомены (dev.mauromarano.it) не работают. – gaggina

ответ

1

Следующая статья не требуется для server блоков:

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

Это должно решить проблему поддомена. В дополнение к этому вам не хватает правил перезаписи для wordpress. Они должны быть следующими:

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

Надеюсь, это очистит вашу проблему. Более подробная информация об этом будет означать более острые решения, поэтому не стесняйтесь комментировать все ошибки, которые у вас есть.

Смежные вопросы