首页 > 系统相关 >nginx

nginx

时间:2023-01-05 16:22:33浏览次数:48  
标签:index http log ssl nginx proxy timeout

目录

try_files

location / {
    try_files $uri $uri/ /index.html;
}

443 强转

if ($ssl_protocol = "") { return 302 https://$host$request_uri; }

vhost配置

listen 80;
listen [::]:80;
listen 443 ssl http2;
listen [::]:443 ssl http2;
ssl_certificate /usr/local/openresty/nginx/conf/ssl/xxx.com.pem;
ssl_certificate_key /usr/local/openresty/nginx/conf/ssl/xxx.com.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ecdh_curve X25519:prime256v1:secp384r1:secp521r1;
ssl_ciphers ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256;
ssl_conf_command Ciphersuites TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256;
ssl_conf_command Options PrioritizeChaCha;
ssl_prefer_server_ciphers on;
ssl_session_timeout 10m;
ssl_session_cache shared:SSL:10m;
ssl_buffer_size 2k;
add_header Strict-Transport-Security max-age=15768000;
ssl_stapling on;
ssl_stapling_verify on;
server_name xxx;
access_log xxx.log combined;
index index.html index.htm index.php;
root xxx;

if ($ssl_protocol = "") { return 302 https://$host$request_uri; }
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|\.env) {
  deny all;
}
location /.well-known {
  allow all;
}

499问题

proxy_ignore_client_abort  on;
# 确定在客户端关闭连接时是否应关闭与代理服务器的连接,而不在等待响应
proxy_read_timeout 600;
proxy_send_timeout 600;
# 如果超时(默认60s),Nginx 会主动断开连接,记录504

7层负载

upstream xxx.cn {
	server  10.x:3050  weight=10 max_fails=3 fail_timeout=3s;
	server  10.x:3050  weight=10 max_fails=3 fail_timeout=3s;

   	check interval=1000 rise=2 fall=3 timeout=5000 type=http default_down=false;
   	check_http_send "GET /services/route/ping HTTP/1.0\r\n\r\n";
   	check_http_expect_alive http_2xx http_3xx;
}

server {
	listen	80;
	server_name  xx.cn;
	index index.html index.htm;
	access_log  /var/log/nginx/xxx.cn.access.log  main;
	error_log   /var/log/nginx/xxx.error.log warn;
	
	location ~ ^/NginxStatus/ {
			stub_status on;
			access_log on;
		}
	location / {
		proxy_redirect off ;
		proxy_set_header Host $host;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header REMOTE-HOST $remote_addr;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_connect_timeout 600;
		proxy_send_timeout 600;
		proxy_read_timeout 600;
		proxy_ignore_client_abort on;
		proxy_buffer_size 1600k;
		proxy_buffers 4 3200k;
		proxy_busy_buffers_size 6400k;
		proxy_temp_file_write_size 6400k;
		proxy_max_temp_file_size 128m;
		proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
		proxy_pass	http://xxx.cn;
	}
}

format json log

log_format main  escape=json '{ "time_local": "$time_local", '
                        '"remote_user": "$remote_user", '
                        '"remote_addr": "$remote_addr", '
                        '"http_referer": "$http_referer", '
                        '"request": "$request", '
                        '"method": "$request_method", '
                        '"url_path": "$request_uri", '
                        '"request_body": "$request_body", '
                        '"status": $status, '
                        '"level": "$level",'
                        '"body_bytes_sent": $body_bytes_sent, '
                        '"http_user_agent": "$http_user_agent", '
                        '"http_host": "$http_host", '
                        '"http_requestid": "$http_requestid", '
                        '"http_authorization": "$http_authorization", '
                        '"business": "ngx_access-$http_host", '
                        '"http_x_forwarded_for": "$http_x_forwarded_for", '
                        '"upstream_addr": "$upstream_addr",'
                        '"trace_id": "$trace_id",'
                        '"upstream_response_time": "$upstream_response_timer",'
                        '"ssl_protocol": "$ssl_protocol",'
                        '"request_time": $request_time'
                        ' }';

标签:index,http,log,ssl,nginx,proxy,timeout
From: https://www.cnblogs.com/liangml/p/nginx.html

相关文章

  • 【Nginx基础知识】详解nginx配置url重定向-反向代理
    【Nginx基础知识】详解nginx配置url重定向-反向代理本文系统:Centos6.5_x64三台主机:nginx主机,hostname:master.lansgg.com IP:192.168.10.128           ......
  • nginx学习笔记
    ​​nginx系列之一:nginx入门​​nginx系列之二:配置文件解读nginx系列之三:日志配置nginx系列之四:web服务器nginx系列之五:负载均衡nginx系列之六:cache服务nginx系列之七:限流......
  • 生产环境下包含refresh_Token接口报错nginx配置
    一、问题现象使用nginx代理项目,生产环境下,包含refresh_Token的接口报错,开发环境下却正常。二、原因nginx默认request的header内容参数下划线时会自动忽略掉,需要添加以下......
  • Nginx配置访问(预览或者,下载)静态资源
    配置方式:在nginx.conf中加上此配置#搭建文件预览 location^~/preview/{autoindexon;alias/intell/image/;#不同OS键入对应path即可#下列配置用于直接下载......
  • NGINX 配置 SSL 双向认证
    NGINX配置SSL双向认证1.1.生成一个CA私钥:ca.keyopensslgenrsa-outca.key40961.2.生成一个CA的数字证书:ca.crt(CommonName随意填写;其它可以填”.”)op......
  • Nginx-常用配置命令
    1.文件上传大小http{ #设置nginx文件上传大小限制 client_max_body_size200M; client_body_buffer_size50M; fastcgi_intercept_errorson;}2.http转https......
  • linux环境通过nginx转发allure报告
    前言:  自动化测试生成的allure报告一般通过jenkins生成,生成后通过jenkins的view账号进行查看,但这样就必须登录jenkins才能看到,如何不通过登录jenkins从而看到allure报告......
  • nginx 配置反向代理和负载均衡
    环境准备主机IPcontrol01192.168.29.128nginx01192.168.29.101nginx02192.168.29.102nginx03192.168.29.103一、配置反向代理control01nginx配......
  • nginx: the "ssl" parameter requires ngx_http_ssl_module in /usr/local/nginx/conf
    Nginx如果未开启SSL模块,配置Https时将提示如题错误原因:nginx缺少http_ssl_module模块,编译安装的时候带上--with-http_ssl_module配置就行了,但是现在的情况是我的nginx已经......
  • 通过xshell在linux上安装nginx1.12.0
    0)环境安装Nginx是C语言开发,建议在Linux上运行,当然,也可以安装Windows版本,本篇则使用CentOS7作为安装环境。 0.1gcc安装安装nginx需要先将官网下载的源码进......