nginx配置虚拟主机
Nginx配置文件特点:
1. Nginx里的配置文件都是以分号;结尾的。
2. 一个server标签就是一个虚拟主机
NGINX配置虚拟主机流程:
1.复制一个完整的server标签段,放在http的结束大括号前。
---------------------------相当于将server标签段放入http标签里
2.更改server_name及对应网页的root根目录
3.检查配置文件语法,平滑重启服务
4.创建server_name对应网页的根目录,并建立测试文件。
----------------------------如果没有index首页会出现403错误
5.在客户端对server_name的主机名做hosts解析DNS配置。
-------------------------------------使用ping检查、浏览器访问
6.在linux服务端做hosts解析,用wget或curl访问
一、编辑nginx主配置文件
进入nginx主配置文件目录下:cd /application/nginx/conf
过滤掉以#开头和空行:egrep -vn "#|^$" nginx.conf >a.log
将源文件备份:mv nginx.conf nginx.conf.ori
修改过滤出来的文件:mv a.log nginx.conf
编辑文件:vim 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.ldwt.org;
root html/www;
index index.html index.htm;
}
server { listen 80; server_name bbs.ldwt.org; root html/bbs; index index.html index.htm; } server { listen 80; server_name blog.ldwt.org; root html/blog; index index.html index.htm; }
}
修改完成后检查语法:../sbin/nginx -t
如果nginx已启动就重启:../sbin/nginx -s reload
如果nginx未启动则启动:../sbin/nginx start
二、创建站点目录:mkdir ../html/{www,bbs,blog}
for n in www bbs blog;do echo "$n.ldwt.com" >../html/$n/index.html;done
for n in www bbs blog;do cat ../html/$n/index.html;done
三、配置客户端hosts文件
———————————————————————————————————
——————————————问题解决:————————————————
重启或启动nginx时报错:
[root@localhost html]# ../sbin/nginx -s reload
nginx: [error] invalid PID number "" in "/application/nginx1.6.2/logs/nginx.pid"
解决:/application/nginx/sbin/nginx -c /application/nginx/conf/nginx.conf
cd ../logs
ll
- nginx的配置、虚拟主机、负债均衡和反向代理(2)
- Linux上nginx安装配置(配置虚拟主机,静态资源)
- nginx虚拟主机,平滑升级更新配置,日至切割
- linux笔记之Nginx虚拟主机的配置
- nginx的基本配置和虚拟主机的配置
- nginx学习笔记4 nginx的配置文件2 虚拟主机的配置
- Nginx安装及配置、负载均衡、反向代理、虚拟主机
- Nginx配置虚拟主机
- nginx配置虚拟主机
- nginx/1.4.6 配置的虚拟主机访问提示“File not found”
- Nginx 虚拟主机 VirtualHost 配置
- nginx虚拟主机配置
- 生产环境下的nginx.conf配置文件(多虚拟主机)
- nginx配置多个虚拟主机,只有其中某个有作用
- Nginx虚拟主机配置实践之nginx访问同一个地址方法(二)
- nginx学习5——配置虚拟主机以,检查nginx配置的方法,windows下的配置
- Nginx实现多虚拟主机配置
- nginx的配置、虚拟主机、负债均衡和反向代理(1)
- Nginx 虚拟主机 VirtualHost 配置
- Nginx虚拟主机配置教程