企业级Ngnix基于域名的配置_server
普通的nginx配置
egrep -v "#|^$" /usr/local/nginx/conf/nginx.conf.default
更改nginx的配置文件-->注意空格和封号
cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak vim /usr/local/nginx/conf/nginx.conf worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name www.baobaotao.com; location / { root html/baobaotao; index index.html index.htm; } } server { listen 80; server_name www.etiantian.com; location / { root html/bbs; index index.html index.htm; } } server { listen 88; server_name www.blog.com; location / { root html/blog; index index.html index.htm; } } }
创建虚拟站点目录
mkdir -p /usr/local/nginx/html/baobaotao mkdir -p /usr/local/nginx/html/etiantian mkdir -p /usr/local/nginx/html/blog echo "www.baobaotao.com" > /usr/local/nginx/html/baobaotao/inhtml echo "www.etiantian.com" > /usr/local/nginx/html/etiantian/index.html echo "www.blog.com" > /usr/local/nginx/html/blog/index.html
检查配置,重启服务
cd /usr/local/nginx/sbin ./nginx -t 【测试ok后重启服务,-t 表示测试】
./nginx -s reload 【测试ok,重启服务】
配置hosts
echo "192.168.25.144 www.baobaotao.com" >> /etc/hosts echo "192.168.25.144 www.etiantian.com" >> /etc/hosts echo "192.168.25.144 www.blog.com" >> /etc/hosts tail /etc/hosts
说明:blog设置的是88端口
作者:小a玖拾柒
-------------------------------------------
个性签名: 所有的事情到最後都是好的,如果不好,那說明事情還沒有到最後~
本文版权归作者【小a玖拾柒】和【博客园】共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利!