nginx普通配置/负载均衡配置/ssl/https配置
1、nginx普通配置
server {
listen 80;
server_name jqlin.lynch.com;
access_log /var/log/nginx/main.log main;
error_log /var/log/nginx/pay_local.error;
#log_format access '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent $request_body "$http_referer" "$http_user_agent" $http_x_forwarded_for';
client_max_body_size 60M;
client_body_buffer_size 512k;
location /apidoc {
alias /usr/share/nginx/html/apidoc;
index index.html;
}
location / {
proxy_pass http://172.16.92.255:8091; # 172.16.92.255为局域网IP,不行用localhost/127.0.0.1替代
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;
}
}
2、nginx负载均衡配置
upstream mysite {
server 172.16.92.255:8092 weight=5; # 172.16.92.255为局域网IP,不行用localhost/127.0.0.1替代
server 172.16.92.255:8091 weight=5; # 172.16.92.255为局域网IP,不行用localhost/127.0.0.1替代
}
server {
listen 80;
server_name jqlin.lynch.com www.jqlin.lynch.com;
access_log /var/log/nginx/main.log main;
error_log /var/log/nginx/pay_local.error;
client_max_body_size 60M;
client_body_buffer_size 512k;
location /apidoc {
alias /usr/share/nginx/html/apidoc;
index index.html;
}
location / {
proxy_pass http://mysite;
}
}
3、nginx ssl/https配置
server {
listen 80;
server_name www.jqlin.lynch.com jqlin.lynch.com;
error_log /usr/share/nginx/html/test/pay_local.error;
client_max_body_size 60M;
client_body_buffer_size 512k;
location / {
root /usr/share/nginx/html/kshop;
index index.html;
autoindex on;
}
}
server {
listen 443 ssl;
server_name www.jqlin.lynch.com jqlin.lynch.com;
error_log /usr/share/nginx/html/test/pay_local.error;
client_max_body_size 60M;
client_body_buffer_size 512k;
location / {
root /usr/share/nginx/html/kshop;
index index.html;
autoindex on;
}
ssl_certificate /etc/nginx/conf.d/fullchain.pem;
ssl_certificate_key /etc/nginx/conf.d/privkey.pem;
}
4、动态代理(a站点反向代理到b站点,a站点为阿里云ng,b站点为百度云ng,注意记得把proxy_set_header Host $host注释掉)
server {
listen 80;
server_name a.xin.com;
#server_name eshopapitest.xinyartech.com;
client_max_body_size 60M;
client_body_buffer_size 512k;
location / {
proxy_pass b.xin.com;;
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;
}
}
5、图片或静态资源配置 server { listen 33068; server_name localhost; client_max_body_size 60M; client_body_buffer_size 512k; location ~ .*\.(gif|jpg|jpeg|png)$ { expires 24h; root /www/html/attachment;#指定图片存放路径 } }