ini nginx.conf

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ini nginx.conf相关的知识,希望对你有一定的参考价值。

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    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  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   75;
    types_hash_max_size 2048;
    server_tokens       off;


    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    include /etc/nginx/conf.d/*.conf;


    add_header          Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
    add_header          X-Content-Type-Options nosniff;
    add_header          X-Frame-Options SAMEORIGIN;
    add_header          X-XSS-Protection "1; mode=block";

    ssl_stapling on;
    ssl_stapling_verify on;

    pagespeed on;
    pagespeed FileCachePath "/path/to/cache";
    pagespeed RewriteLevel OptimizeForBandwidth;
    #优化
    ## 启用压缩空白过滤器
    pagespeed EnableFilters collapse_whitespace;
    # 启用JavaScript库卸载
    pagespeed EnableFilters canonicalize_javascript_libraries;
    # 把多个CSS文件合并成一个CSS文件
    pagespeed EnableFilters combine_css;
    # 把多个JavaScript文件合并成一个JavaScript文件
    pagespeed EnableFilters combine_javascript;
    # 删除带默认属性的标签
    pagespeed EnableFilters elide_attributes;
    # 改善资源的可缓存性
    pagespeed EnableFilters extend_cache;
    # 更换被导入文件的@import,精简CSS文件
    pagespeed EnableFilters flatten_css_imports;
    pagespeed CssFlattenMaxBytes 5120;
    # 延时加载客户端看不见的图片
    pagespeed EnableFilters lazyload_images;
    # 启用JavaScript缩小机制
    pagespeed EnableFilters rewrite_javascript;
    # 启用图片优化机制,可能会压缩你的logo
    # pagespeed EnableFilters rewrite_images;
    # 预解析DNS查询
    pagespeed EnableFilters insert_dns_prefetch;
    # 重写CSS,首先加载渲染页面的CSS规则
    pagespeed EnableFilters prioritize_critical_css;

    #缓存设置
    proxy_cache_path /data/www/cache levels=1:2 keys_zone=one:10m max_size=500m inactive=24h use_temp_path=off;
    # proxy_cache_key "$scheme$request_method$host$request_uri";

    # 开启gzip
    gzip on;
    # 启用gzip压缩的最小文件,小于设置值的文件将不会压缩
    gzip_min_length 1k;
    # gzip 压缩级别,1-10,数字越大压缩的越好,也越占用CPU时间,后面会有详细说明
    gzip_comp_level 2;
    # 进行压缩的文件类型。javascript有多种形式。其中的值可以在 mime.types 文件中找到。
    gzip_types     text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/xml+rss application/json;
    # 是否在http header中添加Vary: Accept-Encoding,建议开启
    gzip_vary on;
    gzip_proxied   expired no-cache no-store private auth;
    # 禁用IE 6 gzip
    gzip_disable "MSIE [1-6]\.";

    #ETag
    etag on;

  server {
    listen              80;
    listen              [::]:80;
    server_name         zinai.xyz www.zinai.xyz;
    return 301          https://zinai.xyz$request_uri;
    return 301          https://www.zinai.xyz$request_uri;
    }

# Settings for a TLS enabled server.

   server {
       listen       443 ssl http2 default_server;
       listen       [::]:443 ssl http2 default_server;
       server_name  zinai.xyz www.zinai.xyz;
       root         /path/to/yoursite;

       ssl_certificate "/path/to/yourcrt";
       ssl_certificate_key "/path/to/yourkey";
       ssl_session_cache shared:SSL:10m;
       ssl_session_timeout  10m;
       ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #按照这个协议配置
       ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE; #按照这个套件配置
       ssl_prefer_server_ciphers on;

       pagespeed SslCertDirectory /etc/pki/tls/certs;
       pagespeed SslCertFile /etc/pki/tls/cert.pem;

       # Load configuration files for the default server block.
       include /etc/nginx/default.d/*.conf;

       location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" {
        add_header "" "";
        }

        location ~ "^/pagespeed_static/" { }
        location ~ "^/ngx_pagespeed_beacon$" { }

        location / {
            proxy_cache one;
            proxy_cache_valid  200 206 304 301 302 10d;
            proxy_cache_key $uri;
            proxy_set_header Host $host:$server_port;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

        #404公益
       error_page 404 /404.html;
        location = /404.html {
          root /path/to/your404page;
        }

       error_page 500 502 503 504 /50x.html;
           location = /50x.html {
       }
   }

}

以上是关于ini nginx.conf的主要内容,如果未能解决你的问题,请参考以下文章

设置NGINX进程分配至多核CPU提升性能

Linux常用命令 查找文件

centos7 nginx1.10 配置文件在哪

nginx服务器绑定多个域名支持pathinfo路由隐藏index.php入口文件

Linux中在当前目录下查找某个文件。

nginx 配置nginx.conf