首页 > 系统相关 >nginx http 通用配置

nginx http 通用配置

时间:2022-10-29 12:11:23浏览次数:89  
标签:http log server nginx add 通用 size listen

文档说明:只记录关键地方;

nginx 配置文件nginx.conf


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


events {
    worker_connections  10240;
}


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

    log_format  main escape=json '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for" '
                      'host:"$host" '
                      'request_uri:"$request_uri" '
                      'upstream_addr: "$upstream_addr" '
                      'upstream_response_time: "$upstream_response_time" '

                      ;


    # underscores_in_headers on;

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;
    server_tokens off;
    resolver  223.5.5.5 223.6.6.6 2400:3200::1 2400:3200:baba::1 ;
    # 关闭IPV6解析
    # resolver  223.5.5.5 223.6.6.6 2400:3200::1 2400:3200:baba::1  ipv6=off;

    gzip  on;
    gzip_vary on;
    gzip_comp_level 6;
    gzip_buffers 4 16k;
    gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/xml text/javascript application/json image/png image/gif image/jpeg;


    proxy_buffer_size  1024k;
    proxy_buffers   32 1024k;
    proxy_busy_buffers_size 1024k;
    proxy_temp_file_write_size 1024k;
    client_body_buffer_size 1024k;
    server_names_hash_bucket_size 256;
    client_max_body_size 50M;

    map_hash_bucket_size 256;

    map $http_upgrade $connection_upgrade {
        default upgrade;
        '' close;
    }
  
    include /etc/nginx/conf.d/*.conf;
}


nginx default.conf


server {
    listen       80;
    listen  [::]:80;
    server_name your-domain;
    rewrite ^(.*) https://$server_name$1 permanent;
}


server {
    listen       443 ssl http2;
    listen  [::]:443 ssl http2;
    server_name  your-domain;

    charset utf-8;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";
    add_header Content-Security-Policy upgrade-insecure-requests;
    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
    add_header Referrer-Policy "no-referrer";

    location / {
            root   html;
            index  index.html index.htm;
        }
    }
}



server {
    listen 443 ssl http2 default_server;
    listen [::]:443 ssl http2 default_server;
    server_name _;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_reject_handshake on; #非服务器名称的 SSL 握手直接拒绝
    return 444;
}

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name _;
    return 444;
}

指定类型的文件设置缓存


location ~* \.(css|js|png|jpg|jpeg|gif|gz|svg|mp4|ogg|ogv|webm|htc|xml|woff)$ {
    
        access_log off;
        add_header    Cache-Control  max-age=360000;
 }

参考文档

  1. nginx features
  2. nginx documentation
  3. HTTP安全
  4. nginx解决跨域关键点
  5. 拷贝nginx容器内配置文件到容器外
  6. nginx TLSv1.3配置
  7. SSL web配置参考网站(SSL Configuration Generator)

标签:http,log,server,nginx,add,通用,size,listen
From: https://www.cnblogs.com/jingjingxyk/p/16838434.html

相关文章

  • C#用FiddlerCore抓包HTTP和HTTPS
    FiddlerCore是收费软件,提供了Fiddler的抓包API,能抓取HTTP和HTTPS的网络请求。官网:https://www.telerik.com/fiddlercore安装FiddlerCore依赖引用有两种方式:1、通过Teleri......
  • 基于C语言的通用型数据结构与容器库
    仓库地址:github:https://github.com/hellototoro/hlibcgitee:https://gitee.com/totorohello/hlibclist双向序列容器,用于将它们的元素保持为线性排列,并允许在序列的任何......
  • 程序引用信任库方式发起https请求
    一、前言OS:Windows1064Tomcat:Tomcat7.0证书格式:.jks格式证书,因为该示例为tomcat方式 二、Tomcat相关配置1、首先你的应用服务器是tomcat的话,需要使用jks证书,没......
  • k3s+traefik+cert-manager+letsencrypt实现web服务全https
    1.简介随着HTTPS不断普及,越来越多的网站都在从HTTP升级到HTTPS,使用HTTPS就需要向权威机构申请证书,需要付出一定的成本,如果需求数量多,也是一笔不小的开支。cert-ma......
  • docker访问外部https数字证书问题
    一般我们构建的docker镜像使用的都是alpinelinux系统,默认是不带ca-certificates根证书的,导致无法识别外部https携带的数字证书。在访问的时候,会抛出​​509:certi......
  • angular入门篇8----Http模块的使用(2):使用接口
    angular入门篇8----Http模块的使用(2):使用接口1.创建Http服务1.1注册HttpClientModule模块我们需要在model.module.ts中注册HttpClientModule模块:\Store\src\app\mod......
  • java http web getToken and login.
    LogInHelper.javapackagecom.yd.dcap.integration.helper;importcom.fasterxml.jackson.annotation.JsonIgnoreProperties;importcom.yd.dcap.integration.EnvConf......
  • 使用CEfSharp之旅(7)CEFSharp 拦截 http 请求 websocket 内容
    废话不多说直接上代码:不清楚的加群:群:191065815privatevoidForm1_Load(objectsender,EventArgse){try{//更改设置......
  • ThreadHttpRequest
    importcom.alibaba.fastjson.JSONArray;importcom.alibaba.fastjson.JSONException;importcom.alibaba.fastjson.JSONObject;importjava.io.IOException;importj......
  • HttpUtils
    importorg.apache.commons.lang3.StringUtils;importorg.apache.http.Consts;importorg.apache.http.HttpEntity;importorg.apache.http.client.entity.UrlEncoded......