# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
# 影响nginx服务器整体运行的配置指令
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
# events 块涉及的指令主要影响 Nginx 服务器与用户的网络连接
events {
# 表示每个 work process 支持的最大连接数为 1024
worker_connections 1024;
}
http {
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 /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65; # 连接超时时间
types_hash_max_size 2048;
include /etc/nginx/mime.types; # 文件扩展名与文件类型映射表
default_type application/octet-stream; # 默认文件类型,默认为text/plain
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
# 这一行表示这个server块监听的端口是80,只要有请求访问了80端口,此server块就处理请求
listen 80 default_server;
# server name 为虚拟服务器的识别路径。因此不同的域名会通过请求头中的HOST字段,匹配到特定的server块,转发到对应的应用服务器中去。
server_name www.alarmclock.com.cn;
# include 指令用于包含拆分的配置文件
include /etc/nginx/default.d/*.conf;
# 访问域名,以及任何没有匹配成功的,都会匹配这里处理. 匹配顺序:= > ^~ > ~ > ~* > 不带符号
location / {
root /data/release; # 设定请求 URL 的本地文件根目录
index index.html index.htm index.php; # 指定网站初始页,nginx会根据文件的枚举顺序来检查
try_files $uri $uri/ @service;
# try_files 会到硬盘里尝试找$uri这个文件,再看有没有$uri/的文件目录,再找不到就会 fall back 到 try_files 的最后一个选项
}
# ~ 区分大小写的正则表达式匹配。匹配所有以.php结尾的请求.($:从字符串末尾进行匹配)
location ~ \.php$ {
root /data/release; # FastCGI子进程保持在内存中并因此获得高效的性能,不会每次请求都fork一个进程
fastcgi_pass 127.0.0.1:9000; # 指定FastCGI服务器监听端口与地址
fastcgi_index index.php; # 如果请求的Fastcgi_index URI是以 / 结束的, 该指令设置的文件会被附加到URI的后面并保存在变量$fastcig_script_name中
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; # 脚本文件请求的路径
include fastcgi_params; # 动态请求转发过程中,客户端的请求参数就是通过fastcgi_params这个文件来传递的
}
# 此种方式的location配置,无法通过外网访问,只能通过内网跳转,实现容错的功能
location @service {
set $suffix "";
if ($uri = /index.php) {
set $suffix "/";
}
proxy_set_header Host $host;
proxy_set_header SERVER_PORT $server_port;
proxy_set_header REMOTE_ADDR $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8000$suffix; # 代理转发
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2 default_server;
# listen [::]:443 ssl http2 default_server;
# server_name _;
# root /usr/share/nginx/html;
#
# ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers PROFILE=SYSTEM;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# location / {
# }
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
}
nginx配置
最新推荐文章于 2023-07-04 15:38:52 发布