博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Niginx简单的配置
阅读量:5307 次
发布时间:2019-06-14

本文共 9214 字,大约阅读时间需要 30 分钟。

#user nobody;

#这里的数值不能超过 CPU 的总核数,因为在单个核上部署超过 1 个 Nginx 服务进程并不起到提高性能的作用。

worker_processes 2;

#nginx进程数,建议按照cpu数目来指定,一般为它的倍数。

#worker_cpu_affinity 00000001 00000010;

#为每个进程分配cpu,上例中将8个进程分配到8个cpu,当然可以写多个,或者将一个进程分配到多个cpu。

worker_rlimit_nofile 102400;

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

#pid logs/nginx.pid;

events {
worker_connections 102400;
}

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

#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 logs/access.log main;

server_names_hash_bucket_size 128;

client_header_buffer_size 1024k;
large_client_header_buffers 4 1024k;
client_max_body_size 64m;
access_log off;
server_tokens off;

keepalive_timeout 600;

sendfile on;

tcp_nopush on;

fastcgi_cache_path E:/06ZhanginProjectServer/nginx-1.13.5/fastcgi_cache levels=1:2

keys_zone=TEST:10m
inactive=5m;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 600;
fastcgi_read_timeout 600;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
fastcgi_cache TEST;
fastcgi_cache_valid 200 302 1h;
fastcgi_cache_valid 301 1d;
fastcgi_cache_valid any 1m;
fastcgi_cache_min_uses 1;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
fastcgi_cache_use_stale error timeout invalid_header http_500;
open_file_cache max=204800 inactive=20s;
open_file_cache_min_uses 1;
open_file_cache_valid 60s;

tcp_nodelay on;

gzip on;
gzip_min_length 5k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;

upstream portalserver {

server 10.0.3.210:8070;
server 10.0.3.210:8180 backup; #热备
}

upstream webserver {

server 10.0.3.210:8071;
server 10.0.3.210:8181 backup; #热备
}

upstream mapiserver {

server 10.0.3.210:8072;
server 10.0.3.210:8182 backup; #热备
}
upstream manageserver {
server 10.0.3.210:8073;
server 10.0.3.210:8183 backup; #热备
}

server {

listen 8894;
server_name localhost test.zhangin.com;
#rewrite ^(.*)\;JSESSIONID=(.*)$ $1 break;
rewrite /service /service.html last;
location = / {
proxy_pass http://portalserver;
}
location ^~ /druid/ {
proxy_set_header Host $host:8894;
proxy_set_header X-Real-Ip $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://portalserver;
}
location ~ .*\.(htm|jsp|cgi|js|sl)?$
{
proxy_set_header Host $host:8894;
proxy_set_header X-Real-Ip $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://portalserver;
client_max_body_size 60m; #允许客户端请求的最大单个文件字节数
client_body_buffer_size 128k; #缓冲区代理缓冲用户端请求的最大字节数,可以理解为先保存到本地再传给用户
proxy_connect_timeout 15; #nginx跟后端服务器连接超时时间(代理连接超时)
proxy_send_timeout 90; #后端服务器数据回传时间(代理发送超时)
proxy_read_timeout 90; #连接成功后,后端服务器响应时间(代理接收超时)
proxy_buffer_size 4k; #代理请求缓存区 这个缓存区间会保存用户的头信息一共Nginx进行规则处理 一般只要能保存下头信息即可
proxy_buffers 4 64k; #同上告诉Nginx保存单个用的几个Buffer最大用多大空间
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k; #proxy 缓存临时文件的大小
proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
proxy_max_temp_file_size 128m;
}
location /hplus/ {
gzip_static on;
expires max;
add_header Cache-Control public;
add_header Access-Control-Allow-Origin *;
}
location ~ .*\.(html|gif|jpg|jpeg|bmp|png|ico|txt|css|swf|eot|otf|ttf|woff|woff2|svg|mp3|mp4|doc|docx|ppt|pptx|xls|xlsx|ipa|apk|mov|flv)?$
{
root E:\06ZhanginProjectServer\ftpZhangin;
expires 7d;
}

error_page 500 502 503 504 /50x.html;

location = /50x.html {
root html;
}
access_log off;
}

server {

listen 8895;
server_name localhost test.zhangin.com;
#rewrite ^(.*)\;JSESSIONID=(.*)$ $1 break;
rewrite /service /service.html last;
location = / {
proxy_pass http://10.0.3.210:8071;
}
location ^~ /druid/ {
proxy_set_header Host $host:8895;
proxy_set_header X-Real-Ip $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://webserver;
}
location ~ .*\.(htm|jsp|cgi|js|sl)?$
{
proxy_set_header Host $host:8895;
proxy_set_header X-Real-Ip $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://webserver;
client_max_body_size 60m; #允许客户端请求的最大单个文件字节数
client_body_buffer_size 128k; #缓冲区代理缓冲用户端请求的最大字节数,可以理解为先保存到本地再传给用户
proxy_connect_timeout 15; #nginx跟后端服务器连接超时时间(代理连接超时)
proxy_send_timeout 90; #后端服务器数据回传时间(代理发送超时)
proxy_read_timeout 90; #连接成功后,后端服务器响应时间(代理接收超时)
proxy_buffer_size 4k; #代理请求缓存区 这个缓存区间会保存用户的头信息一共Nginx进行规则处理 一般只要能保存下头信息即可
proxy_buffers 4 64k; #同上告诉Nginx保存单个用的几个Buffer最大用多大空间
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k; #proxy 缓存临时文件的大小
proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
proxy_max_temp_file_size 128m;
}
location /hplus/ {
gzip_static on;
expires max;
add_header Cache-Control public;
add_header Access-Control-Allow-Origin *;
}
location ~ .*\.(html|gif|jpg|jpeg|bmp|png|ico|txt|css|swf|eot|otf|ttf|woff|woff2|svg|mp3|mp4|doc|docx|ppt|pptx|xls|xlsx|ipa|apk|mov|flv)?$
{
root E:\06ZhanginProjectServer\ftpZhangin;
expires 7d;
}

error_page 500 502 503 504 /50x.html;

location = /50x.html {
root html;
}
access_log off;
}

server {

listen 8896;
server_name test.zhangin.com;
#rewrite ^(.*)\;JSESSIONID=(.*)$ $1 break;
rewrite /service /service.html last;
location ^~ /mobile/ {
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_pass http://webserver;
}
location ^~ /zgj/ {
proxy_set_header Host $host:8896;
proxy_set_header X-Real-Ip $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://portalserver;
}
location ^~ /web/ {
proxy_set_header Host $host:8896;
proxy_set_header X-Real-Ip $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://webserver;
}

location = / {

proxy_pass http://mapiserver;
}
location ^~ /druid/ {
proxy_set_header Host $host:8896;
proxy_set_header X-Real-Ip $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://mapiserver;
}
location ~ .*\.(htm|jsp|cgi|js|sl)?$
{
proxy_set_header Host $host:8896;
proxy_set_header X-Real-Ip $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://mapiserver;
client_max_body_size 10m; #允许客户端请求的最大单个文件字节数
client_body_buffer_size 128k; #缓冲区代理缓冲用户端请求的最大字节数,可以理解为先保存到本地再传给用户
proxy_connect_timeout 15; #nginx跟后端服务器连接超时时间(代理连接超时)
proxy_send_timeout 90; #后端服务器数据回传时间(代理发送超时)
proxy_read_timeout 90; #连接成功后,后端服务器响应时间(代理接收超时)
proxy_buffer_size 4k; #代理请求缓存区 这个缓存区间会保存用户的头信息一共Nginx进行规则处理 一般只要能保存下头信息即可
proxy_buffers 4 64k; #同上告诉Nginx保存单个用的几个Buffer最大用多大空间
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k; #proxy 缓存临时文件的大小
proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
proxy_max_temp_file_size 128m;
}
location ~ .*\.(html|gif|jpg|jpeg|bmp|png|ico|txt|css|swf|eot|otf|ttf|woff|woff2|svg|mp3|mp4|doc|docx|ppt|pptx|xls|xlsx|ipa|apk|mov|dfu|flv)?$
{
root E:\06ZhanginProjectServer\ftpZhangin;
expires 7d;
}

error_page 500 502 503 504 /50x.html;

location = /50x.html {
root html;
}
access_log off;
}

 

server {

listen 8897;
server_name test.zhangin.com;

location = / {

proxy_pass http://manageserver;

}

location ^~ /druid/ {
proxy_set_header Host $host:8897;
proxy_set_header X-Real-Ip $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://manageserver;
}
location ~ .*\.(htm|jsp|cgi|js|sl|txt)?$
{
proxy_set_header Host $host:8897;
proxy_set_header X-Real-Ip $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://manageserver;
client_max_body_size 60m; #允许客户端请求的最大单个文件字节数
client_body_buffer_size 128k; #缓冲区代理缓冲用户端请求的最大字节数,可以理解为先保存到本地再传给用户
proxy_connect_timeout 15; #nginx跟后端服务器连接超时时间(代理连接超时)
proxy_send_timeout 90; #后端服务器数据回传时间(代理发送超时)
proxy_read_timeout 90; #连接成功后,后端服务器响应时间(代理接收超时)
proxy_buffer_size 4k; #代理请求缓存区 这个缓存区间会保存用户的头信息一共Nginx进行规则处理 一般只要能保存下头信息即可
proxy_buffers 4 64k; #同上告诉Nginx保存单个用的几个Buffer最大用多大空间
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k; #proxy 缓存临时文件的大小
proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
proxy_max_temp_file_size 128m;
}
location ~ .*\.(html|gif|jpg|jpeg|bmp|png|ico|css|swf|eot|otf|ttf|woff|woff2|svg|mp3|mp4|doc|docx|ppt|pptx|xls|xlsx|ipa|apk|mov|zip|dfu|flv)$
{
root E:\06ZhanginProjectServer\ftpZhangin;
expires 7d;
}

error_page 500 502 503 504 /50x.html;

location = /50x.html {
root html;
}
access_log off;
}

# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;

# location / {

# root html;
# index index.html index.htm;
# }
#}

# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;

# ssl_certificate cert.pem;

# ssl_certificate_key cert.key;

# ssl_session_cache shared:SSL:1m;

# ssl_session_timeout 5m;

# ssl_ciphers HIGH:!aNULL:!MD5;

# ssl_prefer_server_ciphers on;

# location / {

# root html;
# index index.html index.htm;
# }
#}

}

转载于:https://www.cnblogs.com/ZhouQi-0921/p/10570026.html

你可能感兴趣的文章