#############全局设置项#########################
文件位置:/usr/local/nginx/conf/nginx.conf
#启动子进程的默认用户 初始化安装后是nobody
#可以用命令 useradd -s /sbin/nologin -M nginx 建立一个nginx用户专门给nginx的worker 进程使用 我建立的用户名字是nginx
user nginx;
#Nginx是一个主进程和多个工作进程,工作的模式。工作进程是单进程的,切不需要特殊授权即可运行,这里定义的是工作进程的数量worker的数量,
按照CPU核心数算,例如:单颗CPU,四核心 就写4 如果是2颗CPU 8核心 就写 16)
worker_processes 2;
#全局错误日志的位置和日志的格式(选择三种之一)
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#Nginx的主进程号 保存的位置
#pid logs/nginx.pid;
#
events {
#定义每个工作进程最大的并发数 和上面的worker_processes 数量相乘是本机的共并发数
worker_connections 1024;
}
#############HTTP服务器的配置项##################
http {
#定义mime的类型,类型由mime和type文件定义,定义HTTP支持什么样类型的文件:例如:png jpg 等
include mime.types;
#http默认支持的类型
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"';
#上面变量的说明
#$remote_addr 与 $http_x_forwarded_for 用以记录客户端的IP地址;
#$remote_user 用来记录客户端的用户名称
#$time_local 用来记录访问的时间和时区
#$request 用来记录请求的url与http协议
#$status 用来记录请求的状态,成功是200
#$body_bytes_sent 用来记录发送给客户端文件主体内容的大小
#$http_referer 用来记录从哪个页面链接访问过来的
#$http_user_agent 记录客户端的浏览器的相关信息
#全局日志路径
#access_log logs/access.log main;
#sendfile 指令指定 nginx 是否调用sendfile 函数(zero copy方式) 来输出文件,对于普通用户必须设置为on
sendfile on;
#此选项允许或者禁止使用socke的tcp_CORK的选项,此选项仅在使用sendfile的时候使用
#tcp_nopush on;
#长链接的超时时间
#keepalive_timeout 0;
keepalive_timeout 65;
#开启压缩
#gzip on;
##########以下为配置虚拟主机-只有一个server就是默认网站#######
server {
#虚拟主机使用的端口
listen 80;
#虚拟主机的域名
server_name localhost;
#虚拟主机支持的字符集
#charset koi8-r;
#这个虚拟主机的访问日志路径
#access_log logs/host.access.log main;
#定义WEB根路径(相对路径 相对于自己的安装路径 /usr/local/nginx/)
location / {
#定义此虚拟主机的根路径为htlm目录
root html;
#定义此虚拟主机的索引页
index index.html index.htm;
}
#定义404的错误页
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
#根据错误码 500 502 503 504 返回的错误页
error_page 500 502 503 504 /50x.html;
#定义错误页的路径
location = /50x.html {
#定义错误页面在html里
root html;
}
#定义反向代理服务器 数据服务器是lamp 模型的
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#假如请求匹配.php结尾的页面,直接交给下面的127.0.0.1
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
#定义PHP为本机服务的模型示例
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#拒绝nginx DR 目录及子目录下的.htaccess文件的访问
#location ~ /\.ht {
# deny all;
#}
}
#定义基于端口的虚拟主机的写法
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
#定义https的虚拟主机的写法 需要有证书
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}