• Nginx配置文件(举例)


    编写Nginx主配置文件

    # vim   /usr/local/nginx/conf/nginx.conf
    
    
    user dywww dywww;
    worker_processes auto;
    
    error_log /dydata/wwwlogs/error_nginx.log crit;
    pid /var/run/nginx.pid;
    worker_rlimit_nofile 51200;
    
    events {
      use epoll;
      worker_connections 51200;
      multi_accept on;
    }
    
    http {
      include mime.types;
      default_type application/octet-stream;
      server_names_hash_bucket_size 128;
      client_header_buffer_size 32k;
      large_client_header_buffers 4 32k;
      client_max_body_size 1024m;
      client_body_buffer_size 10m;
      sendfile on;
      tcp_nopush on;
      keepalive_timeout 120;
      server_tokens off;
      tcp_nodelay on;
    
      fastcgi_connect_timeout 300;
      fastcgi_send_timeout 300;
      fastcgi_read_timeout 300;
      fastcgi_buffer_size 64k;
      fastcgi_buffers 4 64k;
      fastcgi_busy_buffers_size 128k;
      fastcgi_temp_file_write_size 128k;
      fastcgi_intercept_errors on;
    
      #Gzip Compression
      gzip on;
      gzip_buffers 16 8k;
      gzip_comp_level 6;
      gzip_http_version 1.1;
      gzip_min_length 256;
      gzip_proxied any;
      gzip_vary on;
      gzip_types
        text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml
        text/javascript application/javascript application/x-javascript
        text/x-json application/json application/x-web-app-manifest+json
        text/css text/plain text/x-component
        font/opentype application/x-font-ttf application/vnd.ms-fontobject
        image/x-icon;
      gzip_disable "MSIE [1-6].(?!.*SV1)";
    
      ##Brotli Compression
      #brotli on;
      #brotli_comp_level 6;
      #brotli_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript image/svg+xml;
    
      ##If you have a lot of static files to serve through Nginx then caching of the files' metadata (not the actual files' contents) can save some latency.
      #open_file_cache max=1000 inactive=20s;
      #open_file_cache_valid 30s;
      #open_file_cache_min_uses 2;
      #open_file_cache_errors on;
    
    ######################## default ############################
      server {
        listen 8080;
        server_name _;
        access_log /dydata/wwwlogs/access_nginx.log combined;
        root /dydata/wwwroot/default;
        index index.html index.htm index.php;
        #error_page 404 /404.html;
        #error_page 502 /502.html;
        location /nginx_status {
          stub_status on;
          access_log off;
          allow 127.0.0.1;
          deny all;
        }
        location ~ [^/].php(/|$) {
          #fastcgi_pass remote_php_ip:9000;
          fastcgi_pass unix:/dev/shm/php-cgi.sock;
          fastcgi_index index.php;
          include fastcgi.conf;
        }
        location ~ .*.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
          expires 30d;
          access_log off;
        }
        location ~ .*.(js|css)?$ {
          expires 7d;
          access_log off;
        }
        location ~ ^/(.user.ini|.ht|.git|.svn|.project|LICENSE|README.md) {
          deny all;
        }
      }
    ########################## vhost #############################
      include vhost/*.conf;
    }

    编写 include  vhost/*.conf 文件

    [root@localhost ~]# vim  /usr/local/nginx/conf/vhost/www.color.com.conf
    server {
      listen 10021 ssl;
      listen 443 ssl;
      #listen 443 ssl;
      #listen [::]:80;
      server_name www.color.com;
      #ssl on;
      ssl_certificate 1_www.color.com_bundle.crt;
      ssl_certificate_key 2_www.color.com.key;
      ssl_session_timeout 5m;
      ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
      ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
      ssl_prefer_server_ciphers on;
      access_log /dydata/wwwlogs/www.color.com_nginx.log combined;
      error_log /dydata/wwwlogs/www.color.com_nginx.err.log;
      index index.html index.htm index.php;
      root /dydata/wwwroot/www.color.com;
    
      include /usr/local/nginx/conf/rewrite/none.conf;
      #error_page 404 /404.html;
      #error_page 502 /502.html;
    location ~* ^/(cms|conf|core|static|tpl|upload|Cashier|download|app_down|house_down|wx-app|runtime|.well-known)/.*.(php|phtml)
    {
            deny all;
    }
    location / {
        if (!-d $request_filename){
            set $rule_0 1$rule_0;
        }
        if (!-f $request_filename){
            set $rule_0 2$rule_0;
        }
        if ($rule_0 = "21"){
            rewrite ^/(.*)$ /index.php?/$1 last;
        }
    }
    location /packapp/plat {
        if (!-f $request_filename){
            set $rule_1 1$rule_1;
        }
        if (!-d $request_filename){
            set $rule_1 2$rule_1;
        }
        if ($rule_1 = "21"){
            rewrite ^.*$  /packapp/plat/index.html last;
        }
    }
    
      location ~ [^/].php(/|$) {
        #fastcgi_pass remote_php_ip:9000;
        fastcgi_pass unix:/dev/shm/php-cgi.sock;
        fastcgi_index index.php;
        include fastcgi.conf;
      }
    
      location ~ .*.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
        expires 30d;
        access_log off;
      }
      location ~ .*.(js|css)?$ {
        expires 7d;
        access_log off;
      }
      location ~ /(.user.ini|.ht|.git|.svn|.project|LICENSE|README.md) {
        deny all;
      }
    }

    编写h5文件

    server {
      #listen 80;
      #listen [::]:80;
      listen 10031;
      server_name h5xhn.dihuangbox.com;
      access_log /dydata/wwwlogs/h5xhn.dihuangbox.com_nginx.log combined;
      index index.html index.htm index.php;
      root /dydata/wwwroot/h5xhn.dihuangbox.com;
    
      include /usr/local/nginx/conf/rewrite/none.conf;
      #error_page 404 /404.html;
      #error_page 502 /502.html;
    
      location ~ [^/].php(/|$) {
        #fastcgi_pass remote_php_ip:9000;
        fastcgi_pass unix:/dev/shm/php-cgi.sock;
        fastcgi_index index.php;
        include fastcgi.conf;
      }
    
      location ~ .*.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
        expires 30d;
        access_log off;
      }
      location ~ .*.(js|css)?$ {
        expires 7d;
        access_log off;
      }
      location ~ /(.user.ini|.ht|.git|.svn|.project|LICENSE|README.md) {
        deny all;
      }
    }

    编写微信公众号wx.color.com.conf文件

    
    
    [root@localhost ~]# vim  /usr/local/nginx/conf/vhost/wx.color.com.conf
    server {
      #listen 80;
      #listen [::]:80;
      listen 10032;
      server_name wx.color.com;
      access_log /dydata/wwwlogs/wx.color.com_nginx.log combined;
      index index.html index.htm index.php;
      root /dydata/wwwroot/wx.color.com;
    
      include /usr/local/nginx/conf/rewrite/none.conf;
      #error_page 404 /404.html;
      #error_page 502 /502.html;
    
    
      location ~ .*.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
        expires 30d;
        access_log off;
      }
      location ~ .*.(js|css)?$ {
        expires 7d;
        access_log off;
      }
      location ~ /(.user.ini|.ht|.git|.svn|.project|LICENSE|README.md) {
        deny all;
      }
    }

    编写api配置文件

    
    
    [root@localhost ~]# vim  /usr/local/nginx/conf/vhost/api.color.com.conf
    server {
      #listen 80;
      #listen [::]:80;
      listen 10022;
      server_name api.color.com;
      access_log /dydata/wwwlogs/api.color.com_nginx.log combined;
      index index.html index.htm index.php;
      root /dydata/wwwroot/api.color.com/public;
    
      include /usr/local/nginx/conf/rewrite/thinkphp.conf;
      #error_page 404 /404.html;
      #error_page 502 /502.html;
    
      location ~ [^/].php(/|$) {
        #fastcgi_pass remote_php_ip:9000;
        fastcgi_pass unix:/dev/shm/php-cgi.sock;
        #root /dydata/wwwroot/api.color.com/public;
        fastcgi_index index.php;
        include fastcgi.conf;
        fastcgi_split_path_info ^(.+?.php)(/.*)$;
        set $path_info $fastcgi_path_info;
        fastcgi_param PATH_INFO $path_info;
        try_files $fastcgi_script_name =404;
      }
    
      location ~ .*.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
        expires 30d;
        access_log off;
      }
      location ~ .*.(js|css)?$ {
        expires 7d;
        access_log off;
      }
      location ~ /(.user.ini|.ht|.git|.svn|.project|LICENSE|README.md) {
        deny all;
      }
    }
  • 相关阅读:
    团队活动
    实力提升
    软工人必须要知道的几个工具
    博客/论坛:(技术分享)
    CSS怎样设置多个字体,设置多个字体的时候要注意什么
    canvas绘制bitmap全部填充(当bitmap的宽高小于绘制区域的时候)
    CSS字体
    weditor元素定位异常
    python ImportError: C extension: DLL load failed while importing strptim
    python:导入不同路径下相同名称的模块
  • 原文地址:https://www.cnblogs.com/haoee/p/13496554.html
Copyright © 2020-2023  润新知