Nginx配置文件
# 配置工作进程运行用户,nobody也是一个linux用户,一般用于启动程序
#user nobody;
#配置工作进程数目。通常为CPU个数,跟随硬件性能调整,如果I/O密集型任务,也就是阻塞式任务较多,可适当增大进程数量。
worker_processes 1;
#错误日志存放路径,默认日志级别是 error,可以调整。
error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
# 配置nginx进程pid存放文件
pid logs/nginx.pid;
# 配置工作模式和连接数
events {
# 每个工作进程的最大连接数量,最大值为 65535, nginx的总连接数量 = worker_processes * worker_connections
worker_connections 1024;
}
# 配置http服务器
http {
# 配置nginx支持的资源类型,可以查在conf/mime.type来查看支持的资源类型
include mime.types;
# 默认文件类型 流类型,可以理解为支持任意类型,即nginx会以流的形式输出
default_type application/octet-stream;
# 配置日志格式 变量main表示
#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的存放路径, 并采用上面的日志格式 main
#access_log logs/access.log main;
# 指定nginx是否调用sendfile函数来输出文件,即是否开启高效文件传输模式
sendfile on;
#tcp_nopush on; # 防止阻塞,一般和sendfile同时使用
#keepalive_timeout 0;
keepalive_timeout 65; # 长连接超时时间,单位是秒
#gzip on; #开启gzip压缩输出
# 配置虚拟主机, 一个http中可以有多个虚拟主机
server {
listen 80; #配置监听端口号
server_name localhost; #配置访问域名,域名可以有多个,用空格隔开
# 需要注意的是 如果存在多个server,则每个server的端口号和域名不能完全一样
# 配置字符集
#charset koi8-r;
# 配置虚拟主机的访问日志
#access_log logs/host.access.log main;
# 匹配的请求路径,此处匹配/,也就是根路径
location / {
# root 表示当请求路径匹配后,nginx服务器将请求映射到的目录
root html; # html 代表nginx在匹配请求后,会将请求映射当前目录的html目录下
index index.html index.htm; # index 代表索引的文件是index.html或者index.htm
}
# 举例
# 此处代表,当请求路径被拦截后,会映射到/opt/image目录下,并返回其中的display.png
location /image {
root /opt;
index display.png
}
# 配置404页面
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
# 配置错误页面
error_page 500 502 503 504 /50x.html;
# 精确匹配
location = /50x.html {
# 访问 50x.html时,前往nginx根目录下的html内寻找资源
root html;
}
}
岁月悠悠,衰微只及肌肤;热忱抛却,颓废必致灵魂