A plurality of server Nginx domain (a domain name or two)

Description of Requirement:

A server (ip: 39.105.1xx.xx) on start nginx, and a plurality of server, a domain name or different each secondary domain.

Implementation (do not say nonsense, directly on the code to read):

Note that I am a two-level domain (.com and .cn)

        server {
                listen 80;
                server_name  testapp.com;
                location / {
                        root /usr/share/nginx/html/official_web/;
                        index  index.html index.htm;
                        # try_files $uri $uri/ /index.html;
                }
        }

        server {
                listen 80;
                server_name  testapp.cn;
                location / {
                        root /usr/share/nginx/html/official_web/zhoubianbaoapp;
                        index  index.html index.htm;
                        # try_files $uri $uri/ /index.html;
                }
        }

In addition, if a plurality of second-level domain, is exactly the same with the above. (Pro-test)

Extension of the problem: oms to configure the system in testapp.com, access path http://testapp.com/oms

Discovery Configuration of http://testapp.com can access, but can not access http://testapp.com/oms, error 404.

The initial configuration is such that (wrong version):

        server {
                listen 80;
                server_name  testapp.com;
                location / {
                        root /usr/share/nginx/html/official_web/;
                        index  index.html index.htm;
                        # try_files $uri $uri/ /index.html;
                }
                ### oms ###
                location  /oms {
                     root /usr/share/nginx/html/oms;
                     index index.html index.htm;
                     # try_files $uri $uri/ /oms/index.html;
                }
                # ......  #
        }

Search for a moment question is: In addition to location / can root, the rest have to set the path for the project on the server using alias (alias).

Modified:

        server {
                listen 80;
                server_name  testapp.com;
                location / {
                        root /usr/share/nginx/html/official_web/; 
                        index  index.html index.htm;
                        # try_files $uri $uri/ /index.html;
                }
                ### oms ###
                location  /oms {
                     alias /usr/share/nginx/html/oms;   #注意就是这一行
                     index index.html index.htm;
                     # try_files $uri $uri/ /oms/index.html;
                }
                # ......  #
        }

So far, the problem is solved.

Guess you like

Origin www.cnblogs.com/martinl/p/12364677.html