Heim  >  Fragen und Antworten  >  Hauptteil

Probleme mit der Korrespondenz zwischen dem virtuellen Nginx-Host und dem Domänennamen der zweiten Ebene

Wie gehen Sie bei der Verwendung von Nginx mit dem entsprechenden Problem zwischen dem virtuellen Host und dem Domänennamen der zweiten Ebene um? Beispielsweise gibt es zwei Domänennamen der zweiten Ebene, die zwei Ordnern entsprechen:

域名         文件夹
111.aa.com   /var/www/111.aa.com
222.aa.com   /var/www/222.aa.com

Dann gibt es in der Konfigurationsdatei zwei entsprechende server,
#111.aa.com

#111.aa.com
server {
    listen       80;
    server_name  111.aa.com;

    charset utf-8;
    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
        root   /var/www/111.aa.com;
        index  index.php index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}


    location ~ \.php$ {
        root           /var/www/111.aa.com;
        fastcgi_pass   unix:/dev/shm/php-fpm.sock;
        try_files $uri /index.php =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param  QUERY_STRING     $query_string;
        include        fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

#222.aa.com

#222.aa.com
server {
    listen       80;
    server_name  222.aa.com;

    charset utf-8;
    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
        root   /var/www/222.aa.com;
        index  index.php index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}


    location ~ \.php$ {
        root           /var/www/222.aa.com;
        fastcgi_pass   unix:/dev/shm/php-fpm.sock;
        try_files $uri /index.php =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param  QUERY_STRING     $query_string;
        include        fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

Frage:
1. Wenn es 100 Second-Level-Domainnamen gibt, müssen wir 100 schreiben server,能否写在1个server中呢,能否给个示例?
2、写100个server和1个server Können Sie ein Beispiel nennen?

2. Wie schreibt man besser 100 🎜 oder 1 🎜? 🎜
某草草某草草2713 Tage vor620

Antworte allen(2)Ich werde antworten

  • 天蓬老师

    天蓬老师2017-05-16 17:19:54

    如果是100个不同的项目, 当然要写100个server(会存在很多定制的情况, 最常见的就是rewrite). 如果是有一个项目对应多个域名的情况, server数量可以减少一些. 即便有方法将100个项目的配置写在一个server里, 那配置文件我估计也会非常复杂, 管理起来会很头疼. 倒不如写100个server来的方便.

    配置 多 不等于 复杂
    配置 多 不等于 复杂
    配置 多 不等于 复杂

    "多" 从来不应该是配置管理担心的事情.

    Antwort
    0
  • ringa_lee

    ringa_lee2017-05-16 17:19:54

    如果配置都差不多,可以通过nginx的变量来判断,这样只要写1个配置就可以了

    可参考的内容:
    http://bneijt.nl/blog/post/name-based-vi...
    http://www.sitepoint.com/set-automatic-v...

    Antwort
    0
  • StornierenAntwort