Nginx配置文件详解

Nginx配置文件详解进入配置文件 cd usr local nginx confvimnginx confNginx 配置文件分为三大块 全局块 events 块 http 块全局块 从配置文件开始到 events 块开始之前的内容 都属于全局块 在全局块中配置的都是影响 Nginx 整体运行的配置 比如说 worker 工作进程 的数量 错误日志的位置等 events 块 events 块主要影响 nginx 服务器与 户的 络连接 如 worker connections1 标识每个 workderproce 进程 持

进入配置文件:

Nginx配置文件分为三大块:全局块,events块,http块

全局块:

events块

 #===================全局块开始====================== #user nobody; #工作进程数,一般配置成和cpu数量一致 worker_processes 1; #全局错误日志及pid文件存放位置 error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #nginx 启动master进程pid号 #pid logs/nginx.pid; #=================全局块结束============================ #==============events块开始====================== events { 
    #标识单个worker进程的最大并发数 worker_connections 1024; } #============events块结束============================ #============http块开始(nginx服务器中配置最频繁的部分,配置虚拟主机,监听端口,请求转发等等)========================== http { 
    #引入 mime 类型定义文件 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压缩 #gzip on; #此处配置多台tomcat服务器(名称不能有下划线:webServer) upstream webServer{ 
    server 127.0.0.1:8081; server 127.0.0.1:8082; } #此处配置多台tomcat服务器(名称不能有下划线:webs2Server) #upstream webs2Server{ 
    #server 192.168.30.19:8083; #server 192.168.32.12:8085; #} server { 
    #定义当前这个server监听的端口 listen 80; #定义使用localhost访问 server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; #默认请求地址,如果请求是:192.168.10.80:80/ 那么会进入这个里面的tomcat反向代理地址 #一个location里面只能有一个proxy_pass location / { 
    #此处可以配置Tomcat反向代理地址比如: #此处可以引用上面upstream 的多台tomcat;也可以单独配置一台 proxy_pass http://127.0.0.1:8081/; #配置单台 #proxy_pass http://webServer/; #引用上面的多台
        #引用上面的多台配置
           # root   html; #默认的网站根目录的位置 #index index.html index.htm; #网站的欢迎页,起始页 } #表示如果请求是:192.168.10.80:80/web 那么会进入这个里面的tomcat反向代理地址 location /web { 
    #此处引用上面的配置的多台tomcat #proxy_pass http://127.0.0.1:8082/; #proxy_pass http://web2Server/; #引用上面的多台Tomcat配置 } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html
        #

        #错误提示页面
        error_page   500 502 503 504 /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; #} } # 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; # 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; # } #} } 
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/208581.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月19日 上午11:15
下一篇 2026年3月19日 上午11:15


相关推荐

  • count(distinct) 与group by 浅析

    count(distinct) 与group by 浅析在传统关系型数据库中,groupby与count(distinct)都是很常见的操作。count(distinctcolA)就是将colA中所有出现过的不同值取出来,相信只要接触过数据库的同学都能明白什么意思。count(distinctcolA)的操作也可以用groupby的方式完成,具体代码如下:selectcount(distinctcolA)fromtable1;selec

    2022年5月11日
    49
  • 交叉线和直通线的区别和用途[通俗易懂]

    交叉线和直通线的区别和用途[通俗易懂]一般设备分为DCE(数据通信设备)和DTE(数据终端设备)当DCE 和DCE以及DTE和DTE之间相连,也就是同种类型的设备相连时间,我们用交叉线。当DCE和DTE之间相连接,也就是不同种类型的设备相连时间,我们一般使用直通线即不同类型的设备需要更简单的连接,不宜是传输复杂化常见的DCE设备(交换机,集线器,CSU/DSU)常见的DTE设备(终端计算机,路由器)

    2022年6月19日
    49
  • JSP_include指令和<jsp:include>

    JSP_include指令和<jsp:include>

    2022年1月6日
    48
  • json字符串,JSONObject对象,JavaBean对象互转。

    json字符串,JSONObject对象,JavaBean对象互转。包名 importnet sf json JSONObject 1 maven 地址 dependency groupId net sf json lib groupId artifactId json lib artifactId version 2 4 version dependency

    2026年3月17日
    2
  • 主定理证明

    主定理证明转自 GoogleSite 算法导论习题解答 先 fork 一下算法导论其实已经给出了具体的证明步骤 但是还是有些省略 此文章是对主定理进行了完全的证明 主定理的证明大致分为两个阶段 1 假设 n 为 b 的整数次幂 如 1 b b 2 b 3 2 不限定 n 的范围 n 可以为任意整数 首先我们先证明第一阶段 即 n b i

    2026年3月17日
    2
  • laravel 时区问题timezone

    laravel 时区问题timezonelaravel 时区问题timezone

    2022年4月24日
    40

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号