2

nginxを始めようとしています。しかし、このコードで何が問題になっているのか本当に理解できません。

ご覧のとおり、2 つのドメインがあります。

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

最初のドメインはワードプレス ブログをホストします。

#####################
# 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;
    }

}

どこが間違っていますか?

私の目標は、この 2 つのドメインを機能させることです。しかし、この方法では、サブドメイン (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 に答える