nginx初始配置优化


一、linux中配置

linux Ngxin如果要使用stream需要额外安装nginx-mod-stream模块

Markup 全选
yum install -y nginx-mod-stream

添加压缩gzip配置 common-gzip.cnf

nginx目录中添加common-gzip.cnf文件,内容为

Markup 全选
gzip on;
gzip_static on;
gzip_min_length 1k;
gzip_comp_level 4;
gzip_proxied any;
gzip_types application/json text/plain application/javascript application/x-javascript text/xml text/css;
gzip_vary on;
gzip_http_version   1.0;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";

添加代理公共配置 common-proxy.conf

存放一些代理的公共配置参数,文件内容为:

Markup 全选
proxy_read_timeout 2400;  # 秒 20分钟 请求超时
# 添加头部信息
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-NginX-Proxy true;
# This is necessary to pass the correct IP to be hashed
real_ip_header X-Real-IP;
proxy_connect_timeout 300;

修改nginx.config

主要作用:

①添加stream节点,从stream.d文件夹中读取配置

②http中设置从config.d文件夹中读取配置

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

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

events {
    worker_connections 1024;
}

stream {
   include /etc/nginx/stream.d/*.conf;
}
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   65;
    types_hash_max_size 4096;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;
    include /etc/nginx/conf.d/*.conf;
}

http跳转配置

http跳转就在conf.d文件夹中添加配置文件,扩展名为conf,例如:

Markup 全选
server {
  listen 29110 ssl;
   # SSL 配置
  ssl_certificate /etc/nginx/ssl/server.crt;
  ssl_certificate_key /etc/nginx/ssl/server.key;
  include /etc/nginx/common-gzip.conf;
  location / {
    proxy_pass https://10.12.8.2:29110;
    include /etc/nginx/common-proxy.conf;
    # 忽略证书验证
    proxy_ssl_verify off;
    proxy_ssl_trusted_certificate /dev/null;  # 或指定自签名证书路径,/dev/null 会忽略验证
  }
}

stream端口转发

在stream.d文件夹中添加配置文件,扩展名为conf

Markup 全选
server {
    listen 8022;  # 外部访问的端口(可以修改为你想要的端口)
    proxy_pass 10.12.8.2:8022;  # 内部 SQL Server 的 IP 和端口
    # proxy_timeout 3600s;             # 超时时间,可根据需要调整
    # proxy_connect_timeout 20s;       # 连接超时时间
}

二、windows中配置

修改nginx.conf配置

C# 全选
#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}

stream {
	include ../vstream/*.conf;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    #log_f
    sendfile        on;
    keepalive_timeout  65;

	gzip on;
	gzip_buffers 32 4K;
	gzip_comp_level 6;
	gzip_min_length 100;
	gzip_proxied any;
	gzip_types application/json text/plain text/xml text/css;
	gzip_vary on;
	gzip_http_version   1.0;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";
  # 设置上传文件的大小
  client_max_body_size 100m;

	include ../vhost/*.conf;
}

http转发配置

在vhost文件夹中添加配置

Markup 全选
server {
  listen 9002;
  root C:\\Users\\Administrator\\Documents\\webs\\ERP\\pc;
  index index.html;
  location / {
    try_files $uri $uri/ /index.html;
  }
  gzip on;
  gzip_buffers 32 4K;
  gzip_comp_level 6;
  gzip_min_length 100;
  gzip_proxied any;
  gzip_types application/json text/plain text/xml text/css;
  gzip_vary on;
  gzip_http_version   1.0;
  gzip_disable "MSIE [1-6]\.(?!.*SV1)";

  # JNPF-START
  # 设置上传文件的大小
  client_max_body_size 100m;

  # 后端服务
  location /server/ {
    proxy_read_timeout 2400;  # 秒 20分钟 请求超时
    proxy_pass http://127.0.0.1:5002/;
    # 添加头部信息
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-NginX-Proxy true;
    # This is necessary to pass the correct IP to be hashed
    real_ip_header X-Real-IP;
    proxy_connect_timeout 300;
  }
}

stream端口转发配置

在vstream文件夹中添加配置

Markup 全选
server {
        listen 14337;  # 外部访问的端口(可以修改为你想要的端口)
        proxy_pass 127.0.0.1:1433;  # 内部 SQL Server 的 IP 和端口
    }

 

 

 

 

版权声明:本文为YES开发框架网发布内容,转载请附上原文出处连接
张国生
上一篇:DBeaver设置
下一篇:RedGate(SQLToolbelt)绕过登录
评论列表

发表评论

评论内容
昵称:
关联文章

nginx初始配置优化
nginx端口转发配置
nginx配置指南
windows Nginx配置开机自启动
nginx配置http自动重定向到https
Nginx部署
C#性能优化总结
CentOS安装nginx
windows下openssl安装,证书生成,nginx配置https以及http重定向https
nginx websocket支持
nginx反向代理https
宝塔系统 nginx位置记录
nginx集群中按照url规则指定节点访问
CentOS7 nginx SSL证书申请并自动续期
nginx安装为windows服务
记一次数据库查询优化记录
使用nuget-server搭建私有Nuget包服务器后,nginx反向代理无法下载包
初始化配置-数据库配置
Anaconda配置
权限配置

联系我们
联系电话:15090125178(微信同号)
电子邮箱:garson_zhang@163.com
站长微信二维码
微信二维码