Nginx添加虚拟主机
2015-08-28 15:09
751 查看
在Nginx中server是http核心模块,通过配置server_name和Listen进行配置虚拟主机。
编辑conf/nginx.conf,直接在Http模块中添加server模块
Tips: 另外如果使用的域名是测试域名,不要忘记在系统的/etc/hosts或C:\Windows\system32\drivers\etc\hosts做域名映射。
先将server模块到一个文件中,再添加到conf/nginx.conf的http模块
在conf下新建一个virtualhost文件夹,创建虚拟主机配置文件a.myhost.conf
打开nginx配置文件conf/nginx.conf,在http范围include虚拟主机配置文件
不带www的域名加301跳转
ServerBlockExample
Nginx多Server反向代理配置
编辑conf/nginx.conf,直接在Http模块中添加server模块
[code]http { server { listen 80 ; server_name www.myhosta.com; access_log logs/myhosta.access.log main; root D:/git-repo/myhost-a; } server { listen 80 default_server;#通过IP访问时默认的服务器 server_name www.myhostb.com; access_log logs/myhostb.access.log main; root D:/git-repo/myhost-b; } }
Tips: 另外如果使用的域名是测试域名,不要忘记在系统的/etc/hosts或C:\Windows\system32\drivers\etc\hosts做域名映射。
先将server模块到一个文件中,再添加到conf/nginx.conf的http模块
在conf下新建一个virtualhost文件夹,创建虚拟主机配置文件a.myhost.conf
[code]server { listen 80; server_name www.myhosta.com; location / { root D:/git-repo/myhost-a; index index.html index.htm; } }
打开nginx配置文件conf/nginx.conf,在http范围include虚拟主机配置文件
[code]include virtualhost/*.conf;
不带www的域名加301跳转
[code]server { listen 80; server_name myhosta.com; rewrite ^/(.*) http://www.myhosta.com/$1 permanent; }
ServerBlockExample
Nginx多Server反向代理配置
相关文章推荐
- nginx 如何安装 nginx_lua_module 模块 以及 echo-nginx-module 模块
- nginx日志配置指令详解
- nginx(四)初识nginx日志文件
- nginx+php(fastcgi)安装教程
- 介绍Nginx
- Linux系统 - 源码编译安装Nginx
- Ubuntu系统安装配置Nginx、PHP、MySQL、ZendGuardLoader服务器环
- nginx+uwsgi+django报502错误分析
- nginx负载均衡基于ip_hash的session粘帖
- nginx中,ip_hash和url_hash的区别
- 解析 Nginx 负载均衡
- ubuntu下nginx的安装教程(过程可能有点不同)
- agentzh 的 Nginx 教程(版本 2015.03.19) 第二篇
- agentzh 的 Nginx 教程(版本 2015.03.19) 第一篇
- centOS linux 下nginx编译安装详解
- nginx php 配置模板
- nginx的站点安全
- nginx的站点安全
- nginx 代理情况下 jsp request.getservername 得不到代理服务器ip
- 如何安装安装nginx软件--nginx的自动安装