个人的小笔记,不好不好
user root;
worker_processes 8;
error_log /var/log/nginx/error.log error;
pid /var/run/nginx.pid;
load_module modules/ngx_http_image_filter_module.so;
events {
worker_connections 16384;
multi_accept on;
use epoll;
}
http {
include /etc/nginx/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 /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
#image cache
proxy_temp_path /mnt/web/temp/images;
#后端的Web服务器可以通过X-Forwarded-For获取用户真实IP
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#==nginx跟后端服务器连接超时时间(代理连接超时)
proxy_connect_timeout 60;
#==连接成功后,后端服务器响应时间(代理接收超时)
proxy_read_timeout 120;
#==后端服务器数据回传时间(代理发送超时)
proxy_send_timeout 20;
#==设置代理服务器(nginx)保存用户头信息的缓冲区大小
proxy_buffer_size 32k;
#==proxy_buffers缓冲区,网页平均在32k以下的设置
proxy_buffers 4 128k;
#==高负荷下缓冲大小(proxy_buffers*2)
proxy_busy_buffers_size 256k;
#==设定缓存文件夹大小,大于这个值,将从upstream服务器传
proxy_temp_file_write_size 256k;
#==1G内存缓冲空间,3天不用删除,最大磁盘缓冲空间2G
proxy_cache_path /home/cache levels=1:2 keys_zone=cache_one:1024m inactive=3d max_size=2g;
client_max_body_size 1024m;
client_body_buffer_size 128k;
#这里默认是4K,改大一点就好了
client_header_buffer_size 16k;
# map 指令定义一个变量,如果有http_upgrade值,则声明connection_upgrade变量
# $connection_upgrade变量默认值为upgrade, 如果$http_upgrade=''就赋值close给connection_upgrade
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 80;
server_name qr.xxxx.cc;
location /xxxx {
proxy_connect_timeout 3;
proxy_send_timeout 30;
proxy_read_timeout 30;
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;
# 下面两个变量必须在这配置,在server外层配置无效
# 如果有websocket,需要额外配置请求头,否则请求头无法被后端拿到
proxy_set_header Upgrade $http_upgrade;
# $connection_upgrade 变量unknown,需要自定义一个map见上面
proxy_set_header Connection $connection_upgrade;
proxy_pass http://localhost:8080/xxxx;
}
location / {
proxy_connect_timeout 3;
proxy_send_timeout 30;
proxy_read_timeout 30;
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_pass http://localhost:8080/xxxx/f/streaming-media/play;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 80;
server_name api.xxx.cc;
#charset koi8-r;
#access_log logs/host.access.log main;
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_set_header REMOTE-HOST $remote_addr;
include /etc/nginx/conf.d/api.conf;
error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 80;
server_name admin.xxx.cc;
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_set_header REMOTE-HOST $remote_addr;
#charset koi8-r;
#access_log logs/host.access.log main;
include /etc/nginx/conf.d/admin.conf;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 80;
server_name xxx.cn www.xxx.cc xxx.cc www.xxx.cn xxx.com.cn www.xxx.com.cn;
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_set_header REMOTE-HOST $remote_addr;
#charset koi8-r;
#access_log logs/host.access.log main;
include /etc/nginx/conf.d/www.conf;
error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 443 ssl;
server_name www.xxxx.cc;
ssl_certificate /etc/nginx/conf.d/cert.crt;
ssl_certificate_key /etc/nginx/conf.d/cert.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
include /etc/nginx/conf.d/ssl.conf;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
upstream xxxCluster {
server localhost:8080 weight=13;
server localhost:18080 backup;
server xx.xx.xx.xx:8080 weight=7;
}
}
include包含的内容如下:
location ~* /userfiles/(.*)\.(jpg|jpeg|gif|png)!(\d+)x(\d+)$ {
expires 24h;
root /mnt/web/upload/xxx/;
#access_log /mnt/file/logs/images_resize_access.log;#日志存放路径
set $w $3;
set $h $4;
image_filter resize $w $h;
image_filter_buffer 50M;
try_files /userfiles/$1.$2 /xxx/userfiles/6.gif;
}
location ~* /file/(.*)\.(jpg|jpeg|gif|png)!(\d+)x(\d+)$ {
expires 24h;
root /mnt/;
access_log /mnt/file/logs/images_resize_access.log;#日志存放路径
set $w $3;
set $h $4;
image_filter resize $w $h;
image_filter_buffer 50M;
try_files /file/$1.$2 /xxx/userfiles/6.gif;
}
location ~* /file/(.*)\.(jpg|jpeg|gif|png)$ {
expires 24h;
root /mnt/;#指定图片存放路径
access_log /mnt/file/logs/images_access.log;#日志存放路径
proxy_store on;
proxy_store_access user:rw group:rw all:rw;
proxy_temp_path /mnt/;#图片访问路径
proxy_redirect off;
proxy_set_header Host $host;
client_max_body_size 50m;
client_body_buffer_size 1280k;
proxy_connect_timeout 900;
proxy_send_timeout 900;
proxy_read_timeout 900;
proxy_buffer_size 40k;
proxy_buffers 40 320k;
proxy_busy_buffers_size 640k;
proxy_temp_file_write_size 640k;
if ( !-e $request_filename)
{
#proxy_pass http://127.0.0.1;#文件不存在时重定向 默认80端口
return 404;
}
}
location ~ ^/(img|js|css|lib)/ {
root /mnt/web/html/;
access_log off;
#expires 30d;
}
location ~ ^/page/.* {
root /mnt/web/html/$1;
index index.html index.htm;
}
location /f {
rewrite ^/f/(.*)$ http://www.xxxxx.cc/f/$1;
}
location /xxxx/x {
proxy_connect_timeout 3;
proxy_send_timeout 30;
proxy_read_timeout 30;
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_pass http://xxxxCluster/xxx;
}
location /x {
proxy_connect_timeout 3;
proxy_send_timeout 30;
proxy_read_timeout 30;
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_pass http://xxxxxCluster/xxx;
}