Nginx配置不同location

两个静态网页配置在不同目录

  • 有一个vue静态网页工程目录放在/home/ubuntu/website/dist,包含index.html和static

  • 另有一个隐私协议静态网页放在/home/ubuntu/website/privacy,包含index.html

配置https://xiangqian.space 指向vue静态网页工程,但是https://xiangqian.space/privacy 指向隐私协议。

nginx.conf里server的location部分配置如下:


location / {

    root /home/ubuntu/website/dist;

    try_files $uri $uri/ /index.html =404;

    index index.html =404;

}

location = /privacy {

    root /home/ubuntu/website/privacy;

    try_files $uri /index.html =404;

    index index.html =404;

}

关键是root写清楚index.html所在的目录,index.html搜索的路径是“{root}+{try_files}”所列举的路径,所以try_files里要写上/index.html

nginx里的其它配置解说可以参考https://blog.csdn.net/qq_33862644/article/details/79337348

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。