企业级Nginx基于虚拟主机别名的设置


生活中访问www.baidu.com和baidu.com是一个效果,同理也可以用rewrite 301跳转的思路(多发了一次请求过去)
配置nginx.conf文件或者include里面的引用的文件,道理相同

1. 配置文件

vim /usr/local/nginx/conf/extra/ etiantian.conf  -->server_name后面空格后添加新的域名
server {
    listen       80;
    server_name  www.etiantian.com  etiantian.com;
    location / {
        root   html/etiantian;
        index  index.html index.htm;
    }
}

检查配置,重启服务
cd /usr/local/nginx/sbin
./nginx -t              【测试ok后重启服务】

配置hosts
echo "192.168.25.144  baobaotao.com" >> /etc/hosts
echo "192.168.25.144  etiantian.com" >> /etc/hosts
echo "192.168.25.144  blog.com" >> /etc/hosts

image

测试

image

猜你喜欢

转载自www.cnblogs.com/ftl1012/p/9296151.html
今日推荐