Nginx配置nginx.conf

阿里云 nginx.conf


user nginx;
worker_processes auto;
worker_rlimit_nofile 65535;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
accept_mutex on;
multi_accept on;
use epoll;
worker_connections 65535;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
charset utf-8;
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# gzip压缩
gzip on;
gzip_min_length 1k;
gzip_comp_level 2;
gzip_buffers 4 16k;
gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript image/jpeg image/gif image/png;
gzip_vary on;
gzip_disable "MSIE [1-6]\.";
server_tokens off; # 隐藏版本号
open_file_cache max=65535 inactive=20s;
open_file_cache_min_uses 1;
open_file_cache_valid 30s;
# limit_conn_zone $server_name zone=limitservers:10m;
# limit_conn_zone $binary_remote_addr zone=limitconn:10m;
# limit_req_zone $binary_remote_addr zone=limitreq:10m rate=40r/s;
server {
listen 80;
server_name molock.cn www.molock.cn;
return 301 https://molock.cn$request_uri;
}
server { # 搭建superset测试demo
listen 80;
server_name superset.molock.cn;
location / {
proxy_pass http://0.0.0.0:8088/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Connection "";
proxy_http_version 1.1;
}
}
server {
listen 443;
server_name www.molock.cn;
ssl on;
ssl_certificate ssl_cert/1_molock.cn_bundle.crt;
ssl_certificate_key ssl_cert/2_molock.cn.key;
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;
return 301 https://molock.cn$request_uri;
}
server {
listen 443;
server_name molock.cn;
ssl on;
ssl_certificate ssl_cert/1_molock.cn_bundle.crt;
ssl_certificate_key ssl_cert/2_molock.cn.key;
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;
# 禁止一些压力测试工具
if ($http_user_agent ~* (webbench|apachebench|siege|http_load)){
return 403;
}
# limit_conn limitservers 3;
# limit_conn limitconn 9;
# limit_req zone=limitreq burst=200;
#limit_rate_after 1024k;
#limit_rate 200k;
root /usr/share/nginx/molockcn;
location / {
fastcgi_connect_timeout 75;
client_body_buffer_size 1024k;
proxy_send_timeout 3600;
proxy_read_timeout 3600;
proxy_connect_timeout 75;
proxy_buffers 32 128k;
proxy_buffer_size 64k;
proxy_busy_buffers_size 128k;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Connection "";
proxy_http_version 1.1;
}
# 返回随机的图片url
location /random {
proxy_pass http://127.0.0.1:8080;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Connection "";
proxy_http_version 1.1;
}
# 禁止访问
location /baidu_urls.txt {
return 404;
}
# 图片
location ~ ^/pictures/ {
root /usr/share/nginx;
expires 30d;
}
# 上传的文件路径
location ~ ^/upload/ {
root /usr/share/nginx;
expires 30d;
}
error_page 404 = /404.html;
}
}