安装完nginx,会生成基础配置文件nginx.conf
[root@web01 nginx]# cat nginx.conf
user www; #nginx运行的用户
worker_processes auto; #nginx worker进程数量(处理web请求)
error_log logs/error.log info; #指定nginx错误文件日志位置及日志模式
pid logs/nginx.pid; #指定nginx进程文件
events {
worker_connections 1024; #每个工作进程并发连接数量
}
#http区域/模块,处理http请求
http {
include mime.types; #引用可支持的(媒体)文件类型,include引用或包含其他地方的配置文件
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; #开启高效传输模式
keepalive_timeout 65; #超时时间
gzip on; #是否压缩
#nginx 虚拟主机配置
server {
listen 80; #web服务监听端口
server_name game.oldboy.com; #web服务器域名
error_page 500 502 503 504 /50x.html;#服务端出错时,提示的错误页面
location = /50x.html {
root /app/code;
}
#用来匹配请求中URI
location / {
root /app/code; #网站站点根目录
index index.html index.htm; #网站站点首页
}
}
include /etc/nginx/conf.d/*.conf; #引入其他.conf结尾的配置文件
}
Nginx 各基础配置详解
一、nginx配置虚拟主机
方法:在conf.d配置目录下新.conf文件指定多个server{}区