美文网首页
Nginx 配置全解析

Nginx 配置全解析

作者: AllAboutCoding | 来源:发表于2019-12-24 15:22 被阅读0次

    最近在学些Nginx,因为自己的小项目需要Nginx配置Web服务器,说起来也是心累,自己一个人写一个项目就需要前后端兼顾,让以前只写移动端的我从前端学些到前端实践再到前端部署上身心疲惫。太多知识需要补充,每次学习都像是进行一次蜕皮,不断的在自己的非舒适区摩擦。以此缘由记录下 nginx 代理服务配置信息的解析,也为了自己更好的查询手册。

    因为所有信息如果全都涵盖的话,篇幅会过长,所以本文会尽量引用互联网上已有的文章作为详细支持
    为了简化,讲用注释的方法简述字段含义

    File location: /usr/local/nginx/conf/nginx.conf

    
    user root; #启动NGINX用户
    
    worker_processes auto; # NGINX进程数,[https://www.cnblogs.com/aaron-agu/p/8003831.html](https://www.cnblogs.com/aaron-agu/p/8003831.html)
    
    #error_log logs/error.log; # Nginx Error log 格式 error_log [file location] [level] 
    
    #error_log logs/error.log notice; # level : debug | info | notice | warn | error | crit | alert | emerg
    
    #error_log logs/error.log info;
    
    #pid logs/nginx.pid; # 指定nginx进程运行文件存放地址
    
    events {
    
     worker_connections 1024; #最大连接数,默认为512
    
    # to be added
    
     accept_mutex on;  #设置网路连接序列化,防止惊群现象发生,默认为on
    
     multi_accept on; #设置一个进程是否同时接受多个网络连接,默认为off
    
     #use epoll; #事件驱动模型,select|poll|kqueue|epoll|resig|/dev/poll|eventport
    
    }
    
    http { #http块
    
     include  mime.types; #文件扩展名与文件类型映射表 [https://blog.csdn.net/Veritas_C/article/details/83897001](https://blog.csdn.net/Veritas_C/article/details/83897001)
    
     default_type application/octet-stream; #默认类型 [https://blog.csdn.net/qq_26711103/article/details/81116900](https://blog.csdn.net/qq_26711103/article/details/81116900)
    
     # 日志规则 [https://my.oschina.net/u/2324318/blog/1938962](https://my.oschina.net/u/2324318/blog/1938962)
    
     #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; # 指定是否使用sendfile系统调用来传输文件。sendfile系统调用在两个文件描述符之间直接传递数据(完全在内核中操作),从而避免了数据在内核缓冲区和用户缓冲区之间的拷贝,操作效率很高,被称之为零拷贝。
    
     #tcp_nopush  on;
    
    # 在 nginx 中,tcp_nopush 配置和 tcp_nodelay "互斥"。它可以配置一次发送数据的包大小。也就是说,它不是按时间累计  0.2 秒后发送包,而是当包累计到一定大小后就发送。在 nginx 中,tcp_nopush 必须和 sendfile 搭配使用。
    
     #tcp_nodelay on; #TCP产生包后直接发送不delay [https://www.jianshu.com/p/cac0a92b9530](https://www.jianshu.com/p/cac0a92b9530)
    
     #keepalive_timeout 0;
    
     keepalive_timeout 65; #断开前长连接时间 [https://blog.csdn.net/weixin_42350212/article/details/81123932](https://blog.csdn.net/weixin_42350212/article/details/81123932)
    
     #gzip on; # gzip压缩
    
     server { #server块
    
     listen  883; #监听端口
    
     server_name localhost; #监听地址
    
     #charset koi8-r; #文本编码格式
    
     #access_log logs/host.access.log main; # 客户端请求日志
    
     location / { # 配置请求的路由,以及各种页面的处理情况 local [url] {} url : 正则匹配域名地址后的字符串,~为区分大小写,~*为不区分大小写。 
    
     root  html; #项目根目录
    
     #proxy_pass http://127.0.0.1:82; # 反向代理地址
    
     index index.html index.htm; #起始网页
    
     }
    
     #error_page 404 /404.html; #http error code 返回 404 错误后跳转的地址 格式: error_page [http_error_code] file
    
     # redirect server error pages to the static page /50x.html
    
     #
    
     error_page  500 502 503 504 /50x.html; #http error code 返回 50X 错误后跳转的地址 格式: error_page [http_error_codes] file
    
     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; # php环境时,配置php反向代理的地址
    
     # fastcgi_index index.php; # php环境时,配置php反向代理的首页
    
     # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # php环境时,配置php反向代理的指令集
    
     # include fastcgi_params;# php环境时,配置php反向代理的指令集包含上面的指令集
    
     #}
    
     # deny access to .htaccess files, if Apache's document root
    
     # concurs with nginx's one
    
     #
    
     #location ~ /\.ht {
    
     # deny all; #拒绝访问 [https://www.cnblogs.com/yyxianren/p/10837189.html](https://www.cnblogs.com/yyxianren/p/10837189.html)
    
     #}
    
     }
    
     # 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; # https 默认端口
    
     # server_name localhost;
    
     # ssl_certificate cert.pem; #申请的https证书 cer 或者pem文件
    
     # ssl_certificate_key cert.key; #申请https证书的key文件
    
     # ssl_session_cache shared:SSL:1m; #ssl握手缓存 [https://www.ioperat.com/news/operation/43.html](https://www.ioperat.com/news/operation/43.html)
    
     # ssl_session_timeout 5m; # 指定客户端可以重用会话参数的时间(超时之后不可使用)
    
     # ssl_ciphers HIGH:!aNULL:!MD5; #SSL加密类型 [https://blog.csdn.net/aa1382525/article/details/84818619](https://blog.csdn.net/aa1382525/article/details/84818619)
    
     # ssl_prefer_server_ciphers on; # 设置协商加密算法时,优先使用服务端的加密套件,而不是客户端浏览器的加密套件
    
     # location / {
    
     # root  html;
    
     # index index.html index.htm;
    
     # }
    
     #}
    
     include /usr/local/nginx/conf/custom/*.conf; #包含 其他conf文件
    
    }
    
    
    
    

    相关文章

      网友评论

          本文标题:Nginx 配置全解析

          本文链接:https://www.haomeiwen.com/subject/dazxoctx.html