Nginx configures different domain names to access different projects

# first method

# go to nginx configuration folder

cd /usr/local/nginx/conf

# edit configuration file

vim nginx.conf

# is modified as follows


......

http {
    ......

    server {
        listen       80;
        server_name  location;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location/{
            root   html/index/;
            index  index.html index.htm;
        }
        ......

    }

    # 访问 www.test1.com 网站,默认解析到 http://ip/test1 项目
    server {
        listen       80;
        server_name  www.test1.com;

        location/{
            root   html/test1/;
            index  index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

    # 访问 www.test2.com 网站,默认解析到 http://ip/test2 项目
    server {
        listen       80;
        server_name  www.test2.com;

        location/{
            alias   html/test2/;
            index  index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

    ......

}

domain name resolution address is the server’s IP, access to nginx will determine which site to request, and then match to the corresponding project

# the second method

# go to nginx configuration folder

cd /usr/local/nginx/conf

# new folder vhost

Create www.test.com.conf

under the folder vhost

server {
    listen       80;
    server_name  www.test.com;

    location/{
        root   html/www.test.com;
        index  index.html index.htm;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }

}

pay attention to change root path (www.test.com come in to visit the project path)
here new www.test.com can be named according to your domain name, according to the above template, Change server_name and root.
. Create a new project name for each project

# go to nginx configuration folder

cd /usr/local/nginx/conf

# edit configuration file

vim nginx.conf

# is modified as follows

......


http {
    ......

    #引入其它配置
    include       vhost/*.conf;

    ......

}

domain name resolution address is the server's IP, access to nginx will determine which site to request, and then match to the corresponding project

reference blog:

  1. configure different Nginx domain names to access different projects

Read More: