Skip to content

Instantly share code, notes, and snippets.

@Mark24Code
Last active June 13, 2020 16:06
Show Gist options
  • Save Mark24Code/d9f23425e8180a3fa1f17a64ba701e6b to your computer and use it in GitHub Desktop.
Save Mark24Code/d9f23425e8180a3fa1f17a64ba701e6b to your computer and use it in GitHub Desktop.
Nginx.conf注释版本
#总体上分成三个部分构成:基本配置、events配置、HTTP配置,以下为配置详情
#------------------------基本配置-------------------------
#user nobody; #配置worker进程运行用户
worker_processes 4; #配置工作进程数目,根据硬件调整,通常等于CPU数量或者2倍于CPU数量
#error_log logs/error.log; #配置全局错误日志及类型,[debug | info | notice | warn | error | crit],默认是error
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid; #配置进程pid文件
#------------------------events配置-------------------------
#配置工作模式和连接数
events {
use epoll; # 优化参数,事件模型,提高性能
worker_connections 1024; #配置每个worker进程连接数上限,nginx支持的总连接数就等于worker_processes * worker_connections
}
#------------------------HTTP配置-------------------------
#配置HTTP服务器,利用它的反向代理功能提供负载均衡支持
http {
#------------------------HTTP基本配置-------------------------
include mime.types; #配置nginx支持哪些多媒体类型,可以在conf/mime.types查看支持哪些多媒体类型
default_type application/octet-stream; #默认文件类型,流类型,流类型意味着任何类型都支持
#配置日志格式,$vars 是内部变量
#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日志及存放路径,并使用上面定义的main日志格式
#access_log logs/access.log main;
sendfile on; #优化参数:开启高效文件传输模式
tcp_nopush on; #优化参数:防止网络阻塞
#keepalive_timeout 0;
keepalive_timeout 65; #长连接超时时间,单位:毫秒
gzip on; #开启gzip压缩输出
#------------------------HTTP_多server配置-------------------------
server {
listen 80; #监听端口
server_name localhost; #配置服务名
#charset utf-8; #配置字符集
#access_log logs/host.access.log main; #配置本虚拟主机的访问日志
#默认的斜杠/的请求,当访问路径中有斜杠/,会被该location匹配到并进行处理
location / {
root html; #root是配置服务器默认网站根目录位置,默认nginx安装主目录下的html
index index.html index.htm; #配置首页文件的名称
}
#error_page 404 /404.html; #配置404错误页
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html; 配置50x错误页面; = 号,指的是精确匹配
location = /50x.html {
root html;
}
# 这是一个PHP的配置
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
# 一旦匹配php的文件,就转发到 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
#
# 当后缀是php转发到 flastcgi服务器
#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的配置。可以平行配置很多,一般大厂会在这里配置几百个
# 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加密传输的例子
# HTTPS server
#
#server {
# listen 443 ssl; # https默认是443端口,http默认是80端口
# server_name localhost;
# ssl_certificate cert.pem; # 证书需要购买
# ssl_certificate_key cert.key; # 证书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;
# }
#}
}
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
#mail {
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
# server {
# listen localhost:110;
# protocol pop3;
# proxy on;
# }
#
# server {
# listen localhost:143;
# protocol imap;
# proxy on;
# }
#}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment