Nginx配置备忘(持续更新)
一些常用配置,方便以后直接copy使用
引入外部配置
http {
include /etc/nginx/conf.d/*.conf;
}
将一个域名绑定到一个实际应用(反向代理)
http {
server {
listen 80;
server_name xxx.bigbrotherlee.com;
location ~/ {
proxy_pass http://127.0.0.1:9004;
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;
}
}
}
ssl
http {
server {
listen 443;
server_name xxx.bigbrotherlee.com;
ssl on;
ssl_certificate certs/XXX.pem;
ssl_certificate_key certs/XXX.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
proxy_pass https://127.0.0.1:8143/;
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 Cookie $http_cookie;
chunked_transfer_encoding off;
}
access_log /var/log/nginx/marketing-api_8143_access.log;
}
}
指定用户
# 默认使用nginx用户执行,要保证有足够的权限
user nginx;
静态资源
http {
server {
listen 80;
server_name localhost;
#access_log /var/log/nginx/host.access.log main;
# 根目录及默认文件
location / {
root /usr/share/nginx/html/dist;
index index.html index.htm;
}
}
}