# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
复制代码
3、修改nginx的工作的家目录
vim /usr/local/nginx/conf/nginx.conf
# 修改location模块
location /xy102 {
root /opt/test1;
index index.html index.htm index.jsp;
}
# 192.168.100.11/opt/xy102/index.html
wq!
nginx -t
mkdir -p /opt/test1/xy102
cd /opt/test1/xy102
echo "天天开心" > index.html
# 注意配置文件里面的字符集需要修改成中文,不然不显示
systemctl restart nginx
页面访问 192.168.100.11/xy102/index.html 访问结果为天天开心
cd /opt/test1
mkdir xy103
echo 456 > index.html
# 修改location下的家目录root为alias
location /xy103 {
alias /opt/test1/xy103;
#alias也是指匹配nginx的工作目录。需要绝对路径
index index.html index.htm index.jsp;
}
wq!
nginx -t
systemctl restart nginx
页面访问 192.168.100.11/xy103 访问结果为456
复制代码
4、root、alias匹配工作目录
root的匹配模式是拼接,root的工作目录,访问的uri /xy102
location /xy102
/opt/test1/xy102/
alias 匹配nginx的工作目录,路径是绝对路径
location/xy102
alias /opt/test1/xy102/;
alias 只能写在http模块当中server模块的location模块里面
root可以写在server模块,也可以在http,也可以在location中
使用alias匹配工作目录不可以使用重定向功能
5、总结