Nginx-虚拟主机
2016-03-29 15:52
489 查看
先准备好两个站点:
配置Nginx:
检测配置文件:
修改本机的hosts文件,通过本机浏览器访问测试效果:
hosts:
浏览器访问test1.com 和test2.com 可以访问到不同的虚拟网站。
更多内容,请关注博主个人博客网站:http://www.whysha.com
# tree test1.com/ test2.com/ test1.com/ └── index.html test2.com/ └── index.html # cat test1.com/index.html test1 test html # cat test2.com/index.html test2 test html
配置Nginx:
# cat nginx.conf #user nobody; worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; tcp_nopush on; keepalive_timeout 65; gzip on; server { listen 80; server_name test1.com; access_log logs/test1.access.log main; location / { root /var/www/test1.com; index index.html index.htm; } } server { listen 80; server_name test2.com; access_log logs/test2.access.log main; location / { root /var/www/test2.com; index index.html index.htm; } } }
检测配置文件:
# /opt/nginx/sbin/nginx -t nginx: the configuration file /opt/nginx/conf/nginx.conf syntax is ok nginx: configuration file /opt/nginx/conf/nginx.conf test is successful重新加载nginx:
# /opt/nginx/sbin/nginx -s reload
修改本机的hosts文件,通过本机浏览器访问测试效果:
hosts:
192.168.78.131 test1.com 192.168.78.131 test2.com
浏览器访问test1.com 和test2.com 可以访问到不同的虚拟网站。
更多内容,请关注博主个人博客网站:http://www.whysha.com
相关文章推荐
- nginx代理指定目录
- 访问Nginx发生SSL connection error的一种情况
- Nginx+Naxsi部署专业级Web应用防火墙
- CentOS 6.2实战部署Nginx+MySQL+PHP
- nginx中http核心模块的配置指令2
- nginx中http核心模块的配置指令3
- nginx中http核心模块的配置指令4
- nginx中http的fastcgi模块的配置指令1
- Nginx 学习笔记(一)
- 网站502与504错误分析
- 用zabbix监控nginx_status状态
- 互联网业内的迷雾 谨慎选择虚拟主机
- 选定虚拟主机 性能凸显优势
- 开通虚拟主机时提示Server.CreateObject失败的解决办法
- 用vbs实现虚拟主机和域名查循的脚本
- 艰难完成 nginx + puma 部署 rails 4的详细记录
- 把Lua编译进nginx步骤方法
- 星外虚拟主机平台国内五大域名接口设置方法
- web 应用中常用的各种 cache详解