zoukankan      html  css  js  c++  java
  • nginx 配置文件详解

      1 #指定nginx运行的用户及用户组,默认为nobody
      2  #user  nobody;   
      3   
      4   #开启的线程数,一般跟逻辑CPU核数一致
      5  worker_processes  1;   
      6 
      7   #定位全局错误日志文件,级别以notice显示,还有debug,info,warn,error,crit模式,debug输出最多,crir输出最少,根据实际环境而定
      8   #error_log  logs/error.log;
      9   #error_log  logs/error.log  notice;
     10   #error_log  logs/error.log  info;
     11   
     12   #指定进程id的存储文件位置
     13   #pid        logs/nginx.pid;
     14   
     15   #指定一个nginx进程打开的最多文件描述符数目,受系统进程的最大打开文件数量限制
     16   #worker_rlimit_nofile 65535
     17   
     18   events {
     19       #设置工作模式为epoll,除此之外还有select,poll,kqueue,rtsig和/dev/poll模式
     20       #use epoll;
     21       
     22       #定义每个进程的最大连接数,受系统进程的最大打开文件数量限制。
     23       worker_connections  1024;
     24   }
     25   
     26   #######Nginx的Http服务器配置,Gzip配置
     27   http {
     28       #主模块指令,实现对配置文件所包含的文件的设定,可以减少主配置文件的复杂度,DNS主配置文件中的zonerfc1912,acl基本上都是用include语句。
     29       include       mime.types;
     30       
     31       #核心模块指令,智力默认设置为二进制流,也就是当文件类型未定义时使用这种方式
     32       default_type  application/octet-stream;
     33   
     34       #下面代码为日志格式的设定,main为日志格式的名称,可自行设置,后面引用
     35       #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
     36       #                  '$status $body_bytes_sent "$http_referer" '
     37       #                  '"$http_user_agent" "$http_x_forwarded_for"';
     38   
     39       #引用日志main
     40       #access_log  logs/access.log  main;
     41   
     42       #设置允许客户端请求的最大的单个文件字节数
     43       #client_max_body_size 20M;
     44       #指定来自客户端请求头的headebuffer大小
     45       #client_header_buffer_size  32k;
     46       #指定连接请求试图写入缓存文件的目录路径
     47       #client_body_temp_path /dev/shm/client_body_temp;
     48       #指定客户端请求中较大的消息头的缓存最大数量和大小,目前设置为4个32KB
     49       #large client_header_buffers 4 32k;
     50       
     51       #开启高效文件传输模式
     52       sendfile        on;
     53       #开启防止网络阻塞
     54       #tcp_nopush     on;
     55       #开启防止网络阻塞
     56       #tcp_nodelay    on;
     57       
     58       #设置客户端连接保存活动的超时时间
     59       #keepalive_timeout  0;
     60       keepalive_timeout  65;
     61   
     62       #设置客户端请求读取超时时间
     63      #client_header_timeout 10;
     64       #设置客户端请求主体读取超时时间
     65       #client_body_timeout 10;
     66       #用于设置相应客户端的超时时间
     67       #send_timeout 
     68       
     69       ####HttpGZip模块配置
     70       #httpGzip modules
     71       #开启gzip压缩
     72       #gzip  on;
     73       #设置允许压缩的页面最小字节数
     74       #gzip_min_length 1k;
     75       #申请4个单位为16K的内存作为压缩结果流缓存
     76       #gzip_buffers 4 16k;
     77       #设置识别http协议的版本,默认为1.1
     78       #gzip_http_version 1.1;
     79      #指定gzip压缩比,1-9数字越小,压缩比越小,速度越快
     80       #gzip_comp_level 2;
     81       #指定压缩的类型
     82       #gzip_types text/plain application/x-javascript text/css application/xml;
     83       #让前端的缓存服务器进过gzip压缩的页面
     84       #gzip_vary on;  
     85       
     86      #########Nginx的server虚拟主机配置
     87       server {
     88           #监听端口为 80
     89           listen       80;
     90           
     91           #设置主机域名
     92           server_name  localhost;   //www.xxx.com或者ip
     93           
     94           #设置访问的语言编码
     95          #charset koi8-r;
     96  
     97          #设置虚拟主机访问日志的存放路径及日志的格式为main
     98          #access_log  logs/host.access.log  main;
     99 
    100          #设置虚拟主机的基本信息
    101          location / {
    102              #设置虚拟主机的网站根目录
    103              root   html;
    104              
    105              #设置虚拟主机默认访问的网页
    106              index  index.html index.htm;
    107          }
    108  
    109          #error_page  404              /404.html;
    110  
    111          # redirect server error pages to the static page /50x.html
    112          #
    113          error_page   500 502 503 504  /50x.html;
    114          location = /50x.html {
    115              root   html;
    116          }
    117  
    118          # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    119          #
    120          #location ~ \.php$ {
    121          #    proxy_pass   http://127.0.0.1;
    122          #}
    123  
    124          # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    125          #
    126          #location ~ \.php$ {
    127          #    root           html;
    128          #    fastcgi_pass   127.0.0.1:9000;
    129          #    fastcgi_index  index.php;
    130          #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    131          #    include        fastcgi_params;
    132          #}
    133 
    134          # deny access to .htaccess files, if Apache's document root
    135         # concurs with nginx's one
    136          #
    137          #location ~ /\.ht {
    138          #    deny  all;
    139         #}
    140      }
    141  
    142  
    143      # another virtual host using mix of IP-, name-, and port-based configuration
    144      #
    145      #server {
    146      #    listen       8000;
    147      #    listen       somename:8080;
    148      #    server_name  somename  alias  another.alias;
    149  
    150      #    location / {
    151      #        root   html;
    152      #        index  index.html index.htm;
    153      #    }
    154      #}
    155  
    156  
    157      # HTTPS server
    158      #
    159      #server {
    160      #    listen       443 ssl;
    161      #    server_name  localhost;
    162  
    163      #    ssl_certificate      cert.pem;
    164      #    ssl_certificate_key  cert.key;
    165  
    166      #    ssl_session_cache    shared:SSL:1m;
    167      #    ssl_session_timeout  5m;
    168  
    169      #    ssl_ciphers  HIGH:!aNULL:!MD5;
    170      #    ssl_prefer_server_ciphers  on;
    171  
    172      #    location / {
    173      #        root   html;
    174      #        index  index.html index.htm;
    175      #    }
    176      #}
    177
    178  }
    179 
    180 

    静态文件:

    在使用nginx+Tomcat 我tomcat为8080端口,使用nginx进行跳转发现网站页面出来了却没显示图片.为此一顿研究;

    发现是uri的问题:一定要注意!!!

    location通过正则表达式来配置可以访问静态资源,通过正则表达式配置location,里面的proxy_pass一定不能有uri,
    
    即配置成:proxy_pass http://192.168.9.12:8081/;
    
    或者
    
    proxy_pass http://192.168.9.12:8081/yiliao_doc;
    
    都是错的~

    下面贴出我参考的小示例子

    网址来源:http://blog.csdn.net/cxm19881208/article/details/65441865

    server {
    
            listen       443;
    
            server_name  doc.wlyl.com;
    
            location /yiliao_doc/ {
    
                    proxy_pass http://192.168.9.12:8081;
    
                    proxy_redirect off ;
    
                    proxy_set_header Host $host;
    
                    proxy_set_header  X-Real-IP  $remote_addr;
    
                    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
    
                    proxy_set_header X-Forwarded-Proto  $scheme;
    
                    proxy_next_upstream error timeout invalid_header;
    
            }
    
            location ~ .*\.(html|htm|ico|png|jpg|jpeg|js|css|bmp)$ {
    
                proxy_pass http://192.168.9.12:8081;
    
           }
    
    
        }

    下面是我nginx+tomcat中配置静态文件重启时出现的问题:

    nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory)
    [root@iZ238uepsriZ sbin]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf   //这里就是指定nginx.conf能生成对应在logs下生成对应的.pid文件
    [root@iZ238uepsriZ sbin]# ./nginx -s reload  //重新载入配置文件nginx.conf  然后就出来了

    下面是我的配置静态文件

    location / {
                root   /home/apache-tomcat-8.5.23/webapps/wzpbk/;
                index  index.html index.htm index.jsp;                    
                proxy_redirect off;
                proxy_pass http://www.wzpbk.com:8080/wzpbk/;  //这里就是由监听到了80端口来跳转到我设置的位置8080和项目路径
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            }
            
            location ~ ^/(images|javascript|js|css|flash|media|static)/ {
            #alias /home/apache-tomcat-8.5.23/webapps/wzpbk;
         root /home/apache-tomcat-8.5.23/webapps/wzpbk;#//指定项目路径 expires 30d; } location
    ~ .*\.(gif|jpg|jpeg|png|bmp|swf|apk|tar.gz)$ { proxy_pass http://ip:8080; expires 30d; } location ~ .*\.(js|css)?$ { proxy_pass http://ip:8080; expires 12h; }

    先写到这里下班了

     

  • 相关阅读:
    向量场中的积分
    Oracle 动态视图4 V$SESSION_WAIT & V$SESSION_EVENT
    Oracle 动态视图3 V$SESSION
    Oracle 动态视图2 V$LOCKED_OBJECT
    Oracle 摘去数据块的面纱
    Oracle 动态视图1 V$LOCK
    Oracle Lock 概述
    Oracle 监听动态注册与静态注册
    Oracle用户进程跟踪
    Oracle SGA参数调整
  • 原文地址:https://www.cnblogs.com/DanBrown/p/8017496.html
Copyright © 2011-2022 走看看