Home > Article > Backend Development > Interpretation of Nginx configuration file nginx.conf
This article mainly introduces the interpretation of the Nginx configuration file nginx.conf. It has a certain reference value. Now I share it with everyone. Friends in need can refer to it.
Open a new configuration of nginx nginx .conf file, the file structure probably looks like this:
#user nobody;worker_processes 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; } http { include mime.types; 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 { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /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; #} } # #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; # } #}}
A lot of codes may seem dazzling, but in fact it is not complicated. Let’s take a look at the simplified version:
# 全局区worker_processes 1; # 有1个工作的worker子进程#可以自行修改,但太大会造成相互争夺CPU,一般来说:子进程数 = CPU数 * 核数# 配置nginx的连接特性events { worker_connections 1024; # 1个worker子进程能同时允许的最大连接数}# http服务器主要段http { # 设定mime类型,类型由mime.types文件定义 include mime.types; default_type application/octet-stream; sendfile on; # 是否调用sendfile来输出文件 keepalive_timeout 65; # 连接超时时间 # 虚拟主机段 server { listen 80; # 监听端口 server_name localhost; # 监听主机\域名\端口 # 定义访问响应 location / { root html; # 根目录定位 index index.html index.htm; # 默认访问页面定位 } # 定义错误提示页面 location = /50x.html { root html; } }
Related recommendations:
Detailed explanation of Nginx configuration file nginx.conf
The above is the detailed content of Interpretation of Nginx configuration file nginx.conf. For more information, please follow other related articles on the PHP Chinese website!