nginx配置

发布时间:2024年01月22日

1、默认conf 引额外配置

include vhosts/*.conf;

2、链接数增加

events {
	worker_connections  51200;
	multi_accept on;
}


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  51200;
	multi_accept on;
}


http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    #keepalive_timeout  0;
    keepalive_timeout  180;
    #tcp_nodelay on;
  fastcgi_connect_timeout 300;
  fastcgi_send_timeout 300;
  fastcgi_read_timeout 300;
  fastcgi_buffer_size 128k;
  fastcgi_buffers 4 128k;
  fastcgi_busy_buffers_size 256k;
  fastcgi_temp_file_write_size 256k;

  #gzip  on;
  gzip on;
  gzip_min_length  4k;
  gzip_buffers     4 32k;
  gzip_http_version 1.1;
  gzip_comp_level 2;
  gzip_types       text/plain application/x-javascript text/css application/xml;
  gzip_vary on;
  gzip_disable "MSIE [1-6].";

  server_names_hash_bucket_size 128;
  client_max_body_size     4m;
  client_header_buffer_size 256k;
  large_client_header_buffers 4 256k;

  server_tokens off;
  autoindex off;

    client_header_timeout       5;
    client_body_timeout         15;
    proxy_connect_timeout      10;
    proxy_send_timeout         30;
    proxy_read_timeout         30;

    #include vhosts.conf;
	include vhosts/*.conf;

}

上图是默认配置

3、额外配置

a、?vhosts.conf


upstream bgdServer{
 server 127.0.0.1:8095 weight=1;
}

upstream kingdomsLogServer{
 server 127.0.0.1:8200 weight=1;
}

upstream casinoLogServer{
 #server 127.0.0.1:8205 max_fails=3 fail_timeout=10s;
 #server 127.0.0.1:8206 max_fails=3 fail_timeout=10s;
 #server 127.0.0.1:9201 weight=1 max_fails=3 fail_timeout=10s;
 #server 127.0.0.1:9202 weight=1 max_fails=3 fail_timeout=10s;
 server 127.0.0.1:9401 weight=1 max_fails=3 fail_timeout=10s;
 server 127.0.0.1:9402 weight=1 max_fails=3 fail_timeout=10s;

}



server {
    listen 80 default_server;
    server_name _;
    return 451;
}

server {
	listen       80;
	server_name  127.0.0.1 localhost 75.2.79.97 99.83.150.31 xxxx.awsglobalaccelerator.com;

	     # 转发
    location / {
        access_log  off;
       index index.jsp;
        proxy_pass   http://bgdServer;
        proxy_redirect             off;
        proxy_set_header           Host $host;
        proxy_set_header           X-Real-IP $remote_addr;
        proxy_set_header           X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}




########################avatar#################
#avatar.xxx.com
server {
	listen       80;
	server_name  avatar.xxx.com;

	root   "C:\softinstall\www\html\avatar";
	#access_log logs/access_land.log;

	location ~ .*\.(js|css|jpg|jpeg|png|bmp|gif)$ {
		access_log  off;
	}
	location / {
		index  index.html index.htm;
	}
}



b、负载均衡

action.xx.com.conf


########################xxLogServer#################
#action.xx.com
server {
	listen       80;
	server_name  action.xx.com;

	root   "C:\softinstall\www\html\official_website\xx";
	#access_log logs/access_land.log;

	location ~ .*\.(js|css|jpg|jpeg|png|bmp|gif)$ {
		access_log  off;
	}
	location / {
		index  index.html index.htm;
	}

}

#action.xx.com - ssl
server {
    listen 443 ssl;
    charset UTF-8;
    server_name  action.xx.com;

    ssl_certificate         "C:/https/action-usakingdoms-com/action.usakingdoms.com_chain.crt";
    ssl_certificate_key     "C:/https/action-usakingdoms-com/action.usakingdoms.com_key.key";
    ssl_trusted_certificate "C:/https/action-usakingdoms-com/action.usakingdoms.com_chain.crt";

    root   "C:/softinstall/www/html/official_website/xx";
    access_log logs/action.xx.com.log;

    location ~ .*\.(js|css|jpg|jpeg|png|bmp|gif)$ {
        access_log  off;
    }

   
     # 转发
    location / {
        access_log  off;
       index index.jsp;
		proxy_pass   http://xxLogServer;
        proxy_redirect             off;
        proxy_set_header           Host $host;
        proxy_set_header           X-Real-IP $remote_addr;
        proxy_set_header           X-Forwarded-For $proxy_add_x_forwarded_for;
    }
   
}

c、普通网站配置

########################bgd.img#################
#bgd.img.xx.com
server {
	listen       80;
	server_name  bgd.img.xx.com;

	root   "C:\softinstall\www\html\bgd";
	#access_log logs/access_land.log;
	add_header Access-Control-Allow-Origin '*';  
        add_header Access-Control-Allow-Credentials "true";
		add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
		add_header Access-Control-Allow-Headers  'token,DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,XRequested-With';
		
	location ~ .*\.(js|css|jpg|jpeg|png|bmp|gif)$ {
		access_log  off;
	}
	location / {
		index  index.html index.htm;
	}
}

文章来源:https://blog.csdn.net/rzrenyu/article/details/135752484
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。