基于域名虚拟主机
wroker_processes 1;#进程数
evevts { #事件区块
worker_connections 1024;#每个work进程支持最大并发
}
http { #http区域开始
include mime.types; #nginx支持媒体类型库文件
default_type application/octet-stream;#默认的媒体类型
sendfile on;#开启高效传输模式
keepalive_timeout 65;#连接超时
server { #第一个server区域,单独的虚拟主机站点
liseten 80;#提供的服务端口
server_nanme www.linuxea.com;#提供服务的域名主机名
location / { # 第一个location区域开始
root /www/www; #站点目录
index index.html index.htm; #默认首页文件
}
}
server {
liseten 80;
server_nanme bbs.linuxea.com;
location / {
root /www/bbs;
index index.html index.htm;
}
}
}
2,站点目录创建
mkdir /www/{www,bbs} -p
基于端口则修改端口即可!基于ip:liseten IPADDR:80;
3,配置管理inginx的include使用
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/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 /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
#nginx_vhost config
include /etc/nginx/conf.d/www.conf;
include /etc/nginx/conf.d/bbs.conf;
include /etc/nginx/conf.d/blog.conf;
}
[root@Rsync conf.d]# cat /etc/nginx/conf.d/www.conf
server {
listen 80;
server_name www.linuxea.com;
location / {
root /www/www;
index index.html index.htm;
}
}
查看
[root@Rsync conf.d]# cat /etc/nginx/conf.d/bbs.conf
server {
listen 80;
server_name bbs.linuxea.com;
location / {
root /www/bbs;
index index.html index.htm;
}
}
[root@Rsync conf.d]# cat /etc/nginx/conf.d/blog.conf
server {
listen 80;
server_name blog.linuxea.com;
location / {
root /www/blog;
index index.html index.htm;
}
}
[root@Rsync conf.d]# mkdir /www/{www,bbs,blog} -p
[root@Rsync conf.d]# echo www.linuxea.com >/www/www/index.html
[root@Rsync conf.d]# echo bbs.linuxea.com >/www/bbs/index.html
[root@Rsync conf.d]# echo blog.linuxea.com >/www/blog/index.html
[root@Rsync conf.d]# curl www.linuxea.com
www.linuxea.com
[root@Rsync conf.d]# curl bbs.linuxea.com
bbs.linuxea.com
[root@Rsync conf.d]# curl blog.linuxea.com
blog.linuxea.com
[root@Rsync conf.d]#
别名:
1,server_name blog.linuxea.com www.blog.linuxea.com;
2,域名解析
[root@Rsync conf.d]# cat /etc/nginx/conf.d/blog.conf
server {
listen 80;
server_name blog.linuxea.com;
location / {
root /www/blog;
index index.html index.htm;
}
}
状态页面:
[root@Rsync conf.d]# cat status.conf
server{
listen 80;
server_name status.linuxea.com;
location / {
stub_status on;
access_log off;
}
}
status.linuxea.comActive connections: 2 --->活动连接数server accepts handled requests 2 2 1 server启动到查看处理的连接accepts成功建立的握手数handled处理的请求数Reading: 1 Writing: 1 Waiting: 0 reading:读取到客户端的header信息数writing:返回给客户端的header信息数waiting:已经处理完成正在等候下一次请求指令的驻留连接,开启keep-alive的情况下,这个值等于active - (reading + writing)