环境
ubuntu 18
nginx1.14
步骤
-
在 /etc/nginx/sites-available/ 中创建名为 weihu 的配置文件
# 复制 test 配置命名为 weihu cp test weihu
-
新增显示网站维护中的index.html,例如放置在 /root/data/www/app/index.html,index.html的路径需写入配置文件中。
-
在 weihu 中进行配置,如下
server { listen 80; server_name 192.168.31.14; location / { root /root/data/www/app/; index index.html; } rewrite ^(.*)$ /index.html break; }
-
通过在 /etc/nginx/sites-enabled 中维护软链接来使想要的配置生效
cd /etc/nginx/sites-enabled # 1. 生效网站配置 # 1.1 删除维护配置链接 rm -f weihu # 1.2 添加网站配置链接 ln -s ../sites-available/test test # 1. 生效维护配置 # 1.1 删除网站配置链接 rm -f test # 1.2 添加维护配置链接 ln -s ../sites-available/weihu weihu