
先看下一份的Nginx 的配置
#user nobody nobody;#使用的用户和组
worker_processes 4;#工作进程的个数,一般等于CPU核数或者总核数的两倍 #error_log logs/error.log;#错误日志的存放路径 错误日志级别有[debug|info|notice|error|warn|crit]
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid;#指定nginx pid 存放的路径 events {
use epoll; #linux 推荐使用epoll freeBBD 推荐kqueue 模型
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;#开启高效文件传输模式,sendfile指令指定nginx是否调用sendfile函数来输出文件,
对于普通应用设为 on,如果用来进行下载等应用磁盘IO重负载应用,可设置为off,以平衡磁盘与网络I/O处理速度,降低系统的负载。注意:如果图片显示不正常把这个改成off。
#tcp_nopush on; #keepalive_timeout 0;
keepalive_timeout 65; #长连接超时时间,单位是秒 gzip on;#启用Gizp压缩
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;#压缩的文件类型 #当前的Nginx的配置
server {
listen 80;#监听80端口,可以改成其他端口
server_name 192.168.0.4;############## 当前服务的域名 #charset koi8-r; #access_log logs/host.access.log main; location / {
root html;
index index.html index.htm;
} }
Nginx 配置文件结构 是
……
events
{
…………………
}
http
{
server{}
server{}
}
Nginx 虚拟主机的配置
基于ip地址的配置
server {
listen 192.168.0.1:80; server_name 192.168.0.1 location / {
root html1; #根目录
index index.html index.htm;#默认页
}
}
#第二个虚拟主机
server {
listen 192.168.0.2:80;#监听的端口和ip
#listen somename:8080;
server_name 192.168.0.2;#主机名 location / {
root html2;
index index.html index.htm;
}
}
基于域名的配置
server {
listen 80; server_name www.a.com; location / {
root html1; #根目录
index index.html index.htm;#默认页
}
}
#第二个虚拟主机
server {
listen 80;
server_name www.b.com; location / {
root html2;
index index.html index.htm;
}
}
基于端口的配置
server {
listen 80; server_name 192.168.0.1; location / {
root html1; #根目录
index index.html index.htm;#默认页
}
}
#第二个虚拟主机
server {
listen 81;
server_name 192.168.0.1; location / {
root html2;
autoindex on;#列出文件目录
index index.html index.htm;
}
}