2

我正在尝试开始使用 nginx。但我无法真正理解这段代码出了什么问题。

如您所见,有 2 个域:

  1. mauromarano.it
  2. 开发者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) 无法正常工作。

4

1 回答 1

1

server块不需要以下子句:

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

这应该解决子域问题。除此之外,您还缺少 wordpress 的重写规则。它们应如下所示:

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

希望这可以解决您的问题。但是,有关它的更多信息将意味着更明确的解决方案,因此请随时评论您仍然存在的任何错误。

于 2013-05-06T19:11:54.137 回答