ini 一个简单的nginx conf文件

Posted

tags:

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

server {
    listen 8001;
    server_name localhost;
    charset utf-8;
    root /opt/celery_web;
    location / { 
        root /opt/celery_web;
    }   
    location ^~ /choi_wan_api/ {
        #add_header 'Access-Control-Allow-Origin' '*';
        #add_header 'Access-Control-Allow-Credentials' 'true';
        #add_header 'Access-Control-Allow-Methods' 'OPTION, POST, GET, PUT, DELETE';
        #add_header 'Access-Control-Allow-Headers' 'X-Requested-With, Content-Type';
        proxy_pass http://localhost:8002;
        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_redirect off;
    }   
    #location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$
    #{  
    #    root /opt/choi-wan/management_web;
    #}  
    access_log /var/log/nginx/access.log;
    error_log  /var/log/nginx/error.log;
}

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文件的主要内容,如果未能解决你的问题,请参考以下文章

ini 另一个nginx.conf

linux 上修改了nginx.conf 怎么重新加载配置文件生效

ini Nginx - /etc/nginx/nginx.conf

ini [nginx conf] nginx简易转发配置#nginx

ini 用于phpmyadmin的Nginx conf

win php nginx 配置小细节