同一个nginx配置文件,请求不同的域名可以指定对应的目录

  • nginx配置
cat long.conf

server {
        listen       80;

        server_name  a.com b.com c.com;


	location / {
		root /home/long/$host/;
		index index.html;
	}


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

   }
  • 创建对应的目录
cd /home/long
mkdir a.com b.com c.com
#对应目录下创建index.html文件
echo 'test a.com' a.com/index.html
...
  • 访问测试
    本地测试,需将nginx所在的ip和域名加入到hosts里
    nginx 请求多个域名指定对应的根目录
    nginx 请求多个域名指定对应的根目录
    nginx 请求多个域名指定对应的根目录

相关文章:

  • 2022-12-23
  • 2021-12-25
  • 2021-12-05
  • 2022-12-23
  • 2021-09-02
  • 2021-07-31
  • 2021-12-02
猜你喜欢
  • 2021-06-17
  • 2022-12-23
  • 2021-11-23
  • 2021-11-08
  • 2021-10-21
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案