# #定义nginx运行的用户各用户组
User Nginx Nginx;
# #nginx进程数, the recommended setting is consistent with the number of CPU cores
Worker_processes 1;
Worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;
# #全局错误日志定义类型 [Debug | info | notice | warn | error | crit]
#error_log Logs/error.log;
#error_log Logs/error.log Notice;
#error_log Logs/error.log Info;
# #一个nginx进程打开的最多文件描述符数目, the theoretical value should be the maximum number of open files (System value ulimit-n) and the number of nginx processes, but the Nginx allocation request is not uniform, so the recommendation is consistent with the value of ulimit-n.
Worker_rlimit_nofile 65535;
# #进程文件
#pid Logs/nginx.pid;
# #工作模式与连接数上限
Events {
# #参考事件模型, use [kqueue | rtsig | epoll |/dev/poll | select | poll]; The Epoll model is a high-performance network I/O model in the Linux version 2.6 kernel, and if it runs on FreeBSD, it uses the Kqueue model.
Use Epoll;
# #单个进程的最大连接数
Worker_connections 65535;
}
# #设置http服务器
HTTP {
# #引入外置配置文件
include/etc/nginx/conf.d/*.conf;
# #文件扩展名与文件类型映射表
Include Mime.types;
# #默认文件类型
Default_type Application/octet-stream;
# #默认编码
#charset Utf-8;
# #服务器名字的hash表大小
#server_name_hash_bucket_size 128;
# #上传文件大小限制 suggest Open
Client_header_buffer_size 32K;
# #设定请求缓存 suggest Open
Large_client_header_buffers 4 64K;
# #最大缓存
Client_max_body_size 20M;
Client_header_timeout 20;
# #日志格式设定
#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指令指定nginx是否调用sendfile函数来输出文件, for normal applications set to ON, if used to download applications such as disk IO heavy load applications, can be set to off to balance disk and network I/O processing speed, Reduce the load on the system. Note: If the picture does not appear normal, change this to off.
Sendfile on;
# #开启目录列表访问, appropriate download server, default off
#autoindex on;
# #防止网络阻塞 suggest Open
Tcp_nopush on;
# #防止网络阻塞 suggest Open
Tcp_nodelay on;
# #长链接超时时间, unit is seconds, 0, no timeout
Keepalive_timeout 65;
# #gzip模块设置
# #开启gzip压缩输出 suggest Open
gzip on;
# #最小压缩文件大小 suggest Open
Gzip_min_length 1k;
# #压缩缓冲区 suggest Open
Gzip_buffers 4 16k;
# #压缩版本 (default 1.1, front End If squid2.5 please use 1.0) suggest open
Gzip_http_version 1.0;
# #压缩等级
Gzip_comp_level 2; Recommended to open
# #压缩类型, the default is already included Textxml, default does not write, write up also no problem, there will be a warn suggest open
Gzip_types text/plain application/x-javascript text/css application/xml;
Gzip_vary on;
# #开启连接限制ip连接数使用
#limit_zone crawler $binary _remote_addr 10m;
# #反向代理缓存Proxy Cache Configuration
Proxy_temp_path/opt/cache/nginx/temp;
Proxy_cache_path/opt/cache/nginx/cache levels=1:2 keys_z inactive=1d max_size=2g;
Proxy_cache_path/opt/cache/nginx/proxy_cache_image levels=1:2 keys_z inactive=1d max_size=10g;
Proxy_connect_timeout 30;
Proxy_read_timeout 60;
Proxy_send_timeout 20;
Proxy_buffer_size 96k;
Proxy_buffers 8 256k;
Proxy_busy_buffers_size 512k;
Proxy_temp_file_write_size 512k;
#proxy_cache_path配置
#keys_z indicates that the zone name is Infcache and the allocated memory size is 600MB
#/opt/cache/nginx/cache indicates the directory where the cache file for this zone is to be stored
#levels =1:2 indicates that the first level directory of the cache directory is 1 characters, and the second level is 2 characters, that is,/data/ngx_cache/cache1/a/1b this form
#inactive =1D indicates that the cache file in this zone will be deleted by the cache manager process if it is not accessed within 1 days
#max_size =10g indicates that the zone's hard drive capacity is 10GB
# #FastCGI相关参数是为了改善网站的性能: Reduce resource usage and increase access speed.
Fastcgi_connect_timeout 300;
Fastcgi_send_timeout 300;
Fastcgi_read_timeout 300;
Fastcgi_buffer_size 64k;
Fastcgi_buffers 4 64k;
Fastcgi_busy_buffers_size 128k;
Fastcgi_temp_file_write_size 128k;
# #负载均衡, weight weights, the higher the weight, the greater the chance of being assigned.
Upstream myserver{
Server 192.168.1.10:8080 weight=3;
Server 192.168.1.11:8080 weight=4;
Server 192.168.1.12:8080 weight=1;
}
# #虚拟主机配置
server {
# #监听端口
Listen 80;
# #域名可以有多个, separated by a space
server_name localhost;
#charset Koi8-r;
# #定义本虚拟主机的访问日志
#access_log Logs/host.access.log Main;
Location/{
root HTML;
Index index.html index.htm;
}
# #图片缓存时间设置
Location ~.*. (gif|jpg|jpeg|png|bmp|swf) ${
Expires 10d;
}
# #js和CSS缓存时间设置
Location ~.*. (JS|CSS)? ${
Expires 1h;
}
#error_page 404/404.html;
# REDIRECT Server error pages to the static page/50x.html
#error_page 502 503 504/50x.html;
Location =/50x.html {
root HTML;
}
# Proxy The PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# Proxy_pass http://127.0.0.1;
#}
# 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
#
#location ~/\.ht {
# Deny All;
#}
# #对 "/" Enable reverse Proxy
Location/{
# #或者使用
#proxy_pass http://MyServer;
Proxy_pass http://127.0.0.1:88;
Proxy_redirect off;
Proxy_set_header x-real-ip $remote _addr; #后端的Web服务器可以通过X-forwarded-for get the user real IP
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
#以下是一些反向代理的配置, optional.
Proxy_set_header Host $host;
Client_max_body_size 10m; #允许客户端请求的最大单文件字节数
Client_body_buffer_size 128k; #缓冲区代理缓冲用户端请求的最大字节数,
Proxy_connect_timeout 90; #nginx跟后端服务器连接超时时间 (proxy connection timed out)
Proxy_send_timeout 90; #后端服务器数据回传时间 (proxy send timeout)
Proxy_read_timeout 90; #连接成功后, back-end server response time (proxy receive timeout)
Proxy_buffer_size 4k; #设置代理服务器 (nginx) buffer size for saving user header information
Proxy_buffers 4 32k; #proxy_buffers缓冲区, the average Web page is set below 32k
Proxy_busy_buffers_size 64k; #高负荷下缓冲大小 (proxy_buffers*2)
Proxy_temp_file_write_size 64k; #设定缓存文件夹大小, greater than this value, will be passed from the upstream server
}
# #设定查看Nginx状态的地址
Location/nginxstatus {
Stub_status on;
Access_log on;
Auth_basic "Nginxstatus";
Auth_basic_user_file confpasswd;
#htpasswd文件的内容可以用apache提供的htpasswd工具来产生.
}
# #本地动静分离反向代理配置
#所有jsp的页面均交由tomcat或resin处理
Location ~. (JSP|JSPX|DO)? $ {
Proxy_set_header Host $host;
Proxy_set_header X-real-ip $remote _addr;
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
Proxy_pass http://127.0.0.1:8080;
}
# #所有静态文件由nginx直接读取不经过tomcat或resin
Location ~. *. (HTM|HTML|GIF|JPG|JPEG|PNG|BMP|SWF|IOC|RAR|ZIP|TXT|FLV|MID|DOC|PPT|PDF|XLS|MP3|WMA) $
{Expires 15d;}
Location ~. *. (JS|CSS)? $
{Expires 1h;}
}
}
The above describes the arrangement of nginxconf configuration details, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.