#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区块结束
サーバーモジュールの役割(各サーバーには場所が必要です):
1。ドアでゲストを迎えるのを待っているウェイターと同様に、複数のサーバーがあり、複数のウェイターがあります。サービス監視情報を構成します
。2。ホスト情報によると、ゲストの居場所のウェイターの取り決めに従って、どのウェイターがゲストを受け入れるかを確認します。3
。最後に、処理のためにロケーションウェイターに渡します。
ロケーションモジュールの機能:
1。UR情報の検索
2.検索場所の指定
3.指定された情報がある場合は、指定された情報に対応します。指定された情報がない場合は、index.htmlに応答します。デフォルトでは。
場所〜.php $ { ルートhtml; fastcgi_pass 127.0.0.1:9000; //定义反向defastcgi_indexindex.php; fastcgi_param SCRIPT_FILENAME / scripts $ fastcgi_script_name; fastcgi_paramsを含める; }
注:LNMPアーキテクチャが別々のプラットフォームにデプロイされている場合、「/ scripts」をphpディレクトリに置き換える必要があります