Nginx反向代理配置
1.Java接口反向代理配置
server
{
listen 80;
server_name api.hungry-english.com;
#后台静态路径配置
location / {
root /service/app/hunger_server/master;
try_files $uri $uri/ /index.html?q=$uri&$args;
index index.html index.htm;
}
#后台接口配置 默认所有接口都以hunger开头
location /hunger {
proxy_pass http://127.0.0.1:4000;
client_max_body_size 100m;
proxy_buffer_size 512k;
proxy_buffers 32 32k;
proxy_busy_buffers_size 512k;
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 Accept-Encoding "";
}
}
2.Web 页面配置
server
{
#开启和关闭gzip模式
gzip on;
#gizp压缩起点,文件大于1k才进行压缩
gzip_min_length 1k;
# gzip 压缩级别,1-9,数字越大压缩的越好,也越占用CPU时间
gzip_comp_level 6;
# 进行压缩的文件类型。
gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/xml text/javascript application/json image/png image/gif image/jpeg;
#nginx对于静态文件的处理模块,开启后会寻找以.gz结尾的文件,直接返回,不会占用cpu进行压缩,如果找不到则不进行压缩
# gzip_static on|off
# 是否在http header中添加Vary: Accept-Encoding,建议开启
gzip_vary on;
# 设置压缩所需要的缓冲区大小,以4k为单位,如果文件为7k则申请2*4k的缓冲区
gzip_buffers 4 16k;
# 设置gzip压缩针对的HTTP协议版本
# gzip_http_version 1.1;
listen 80;
server_name manager.hungry-english.com;
# web项目打包路径
location / {
root /service/app/hunger_server/frontEnd/mgmt;
try_files $uri $uri/ /index.html?q=$uri&$args;
index index.html index.htm;
}
}
3.Nginx HTTPS配置
server
{
#开启和关闭gzip模式
gzip on;
#gizp压缩起点,文件大于1k才进行压缩
gzip_min_length 1k;
# gzip 压缩级别,1-9,数字越大压缩的越好,也越占用CPU时间
gzip_comp_level 6;
# 进行压缩的文件类型。
gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/xml text/javascript application/json image/png image/gif image/jpeg;
#nginx对于静态文件的处理模块,开启后会寻找以.gz结尾的文件,直接返回,不会占用cpu进行压缩,如果找不到则不进行压缩
# gzip_static on|off
# 是否在http header中添加Vary: Accept-Encoding,建议开启
gzip_vary on;
# 设置压缩所需要的缓冲区大小,以4k为单位,如果文件为7k则申请2*4k的缓冲区
gzip_buffers 4 16k;
# 设置gzip压缩针对的HTTP协议版本
# gzip_http_version 1.1;
listen 80;
listen 443 ssl;
server_name hunger.30days-tech.com;
location / {
root /service/app/hunger_server/frontEnd/mgmt/;
}
# PEM 和KEY 可从阿里云免费申请 需要绑定对应的域名
ssl_certificate /usr/local/nginx/ssl/hunger.30days-tech.com/4595717_hunger.30days-tech.com.pem;
ssl_certificate_key /usr/local/nginx/ssl/hunger.30days-tech.com/4595717_hunger.30days-tech.com.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 /hunger {
proxy_pass http://127.0.0.1:4000;
client_max_body_size 100m;
proxy_buffer_size 128k;
proxy_buffers 32 32k;
proxy_busy_buffers_size 128k;
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 Accept-Encoding "";
}
}