#user nobody;
worker_processes 1; <- worker进程的数量,为了避免上下文切换,通常设置为cpu总核数-1或等于总核数
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events { <- 事件区块开始
worker_connections 1024; <- 每一个worker进程支持的最大连接数(相当于一个服务员能服务多少个客人)
}
http { <- HTTP区块开始
include mime.types; <- Nginx支持的媒体类型库文件
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; <- 开启高效传输模式
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65; <- 连接超时
#gzip on;
server { <- 第一个Server区块开始,表示一个独立的虚拟机站点
listen 80; <- 提供服务的端口,默认为80(响应请求的端口)
server_name localhost; <- 提供服务的域名主机名
#charset koi8-r;
#access_log logs/host.access.log main;
location / { <- 第一个location区块开始
root html; <- 站点的根目录,相当于Nginx的安装目录
index index.html index.htm; <- 默认的首页文件,多个用空格分开
} <- 第一个location区块结束
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html; <- 出现对应的http状态码时,使用50x.html回应客户
location = /50x.html { <- location区块开始,访问50x.html
root html; <- 指定对应的站点目录为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;
#}
}
# 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 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;
# }
#}
} <- HTTP区块结束
The role of the server module (each server must have a location):
1. Similar to waiters waiting to receive guests at the door, there are multiple servers, there are multiple waiters; configure service monitoring information
2. According to the host information, confirm that it is Which waiter receives the guests, according to the waiter's arrangement of the guests' whereabouts
3. Finally, hand it over to the location waiter for processing
The function of the location module:
1. Find UR information
2. Specify where to find it.
3. If there is a specified information, it corresponds to the specified information. If there is no specified information, it will respond to index.html by default.
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;
}
Note: When the LNMP architecture is deployed on separate platforms, "/scripts" needs to be replaced with the php directory