# yum -y install epel-release
# yum -y install nginx
tree
命令查看Nginx
主体配置结构# tree /etc/nginx/
.
├── conf.d #辅助配置文件
├── default.d #通用(默认)配置文件
├── fastcgi.conf #fastcgi相关变量配置文件,一般作用于以PHP-FPM为后端解释器场景,下同
├── fastcgi.conf.default #
├── fastcgi_params #fastcgi相关变量配置文件,一般作用于以PHP-FPM为后端解释器场景,下同
├── fastcgi_params.default
├── koi-utf
├── koi-win
├── mime.types #gzip文件压缩类型对照表,作用于显式开启gzip功能时;是系统自带的 /etc/mime.types 文件的子集
├── mime.types.default
├── nginx.conf #Nginx主配置文件
├── nginx.conf.default
├── scgi_params #scgi相关变量配置文件,下同
├── scgi_params.default
├── uwsgi_params #uwsgi #uwsgi相关变量配置文件,一般同基于Python的Web框架(eg: Flask/Django)协同工作,下同
├── uwsgi_params.default
└── win-utf
2 directories, 15 files
[root@Center nginx]# less nginx.conf
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx; # 以指定用户身份运行worker process(工作进程)
worker_processes auto; # worker process数量,建议 ≤ CPU核心数,auto表示等于CPU核心数
error_log /var/log/nginx/error.log; #错误日志存储路径
pid /run/nginx.pid; #主进程文件目录(PID文件)
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf; #动态模块配置文件
events {
worker_connections 1024; #每个worker process所能够接受的最大并发连接数,建议使用默认值
}
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; #开启sendfile功能
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65; #长连接超时时长
types_hash_max_size 2048;
gzip on; #开启gzip压缩功能
include /etc/nginx/mime.types;
default_type application/octet-stream;
# 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 { #定义一个虚拟主机
listen 80 default_server; #监听服务端口(IPv4),default_server表示当无匹配的server时,当前server为默认响应server(注:1个Nginx实例仅允许存在1个default_server声明)
listen [::]:80 default_server; #同上,此处为IPv6相关配置
server_name t.zhimajihua.cn; #域名
root /usr/share/nginx/html; #站点根目录
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf; #引用通用(默认)配置文件
location / { #定义location
root html; #匹配根目录时,站点主目录路径
index index.html index.htm; #默认首页名称,从左到右匹配
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#当用户请求任意以 .php 为后缀的页面时,代理到特定后端主机;也可以应用在HTTPS配置段
location ~ \.php$ {
proxy_pass http://127.0.0.1; #反代到特定后端主机,格式形如:proxy_pass http://IP:PORT;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#fastcgi反代;也可以应用在HTTPS配置段
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000; #处理fastcgi请求的后端主机地址
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; #该处指明的路径将用于匹配 require_url 的相对路径,/scripts应替换为站点根目录路径或$document_root(推荐)
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
error_page 404 /404.html; #定义匹配特定错误码时,错误页路径,下同
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
# HTTPS相关配置段
# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2 default_server; #监听本地443(IPv4)端口,使用SSL/TLS协议加密,启用http2协议(如客户端不支持将自动向前适应 HTTP/1.1 )
# listen [::]:443 ssl http2 default_server; #IPv6相关
# server_name t.zhimajihua.cn;
# root /usr/share/nginx/html;
#
# ssl_certificate "/etc/pki/nginx/server.crt"; #SSL证书路径
# ssl_certificate_key "/etc/pki/nginx/private/server.key"; #SSL证书私钥路径
# ssl_session_cache shared:SSL:1m; #SSL会话缓存配置
# ssl_session_timeout 10m; #SSL会话超时时长,默认10min
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# location / {
root /usr/share/nginx/html;
# }
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
}