nginx.conf 主配置文件配置详情
user nobody;
worker_processes 2;
events {
worker_connections 10240;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
#include nginx1.conf;
include nginx-other.conf;
include /home/zqcn/zh.conf;
server {
listen 8081;
server_name localhost;
# location ~/group([0-9])/M00 {
# ngx_fastdfs_module;
# }
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
nginx1.conf
server {
listen 8666;
server_name 0.0.0.0 localhost;
client_body_buffer_size 20m;
client_max_body_size 1024m;
proxy_buffer_size 512k;
proxy_buffers 4 512k;
proxy_busy_buffers_size 512k;
proxy_temp_file_write_size 512k;
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
//反向代理java服务
location /clue {
# add_header 'Access-Control-Allow-0rigin' '*' ;
proxy_pass http://localhost:9001/clue;
#proxy_pass http://localhost:9004/clue_other;
}
//测试环境
location /clue-test {
# add_header 'Access-Control-Allow-0rigin' '*' ;
proxy_pass http://localhost:9002/clue-test;
}
//动静分离
location /clue-web-test {
alias /iflytek/chark/clue/test/web/dist;
}
location /clue-web {
alias /iflytek/chark/clue/web/dist;
}
//管理端页面
location /clue-admin {
alias /iflytek/chark/clue/admin/dist;
}
}
nginx-other.conf
server {
listen 8666;
server_name 0.0.0.0 localhost;
client_body_buffer_size 20m;
client_max_body_size 1024m;
proxy_buffer_size 512k;
proxy_buffers 4 512k;
proxy_busy_buffers_size 512k;
proxy_temp_file_write_size 512k;
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
location /clue-test {
# add_header 'Access-Control-Allow-0rigin' '*' ;
proxy_pass http://localhost:9002/clue-test;
}
//生产环境-动态切换此配置
location /clue {
# add_header 'Access-Control-Allow-0rigin' '*' ;
#proxy_pass http://localhost:9001/clue;
proxy_pass http://localhost:9004/clue_other;
}
//动静分离
location /clue-web-test {
alias /iflytek/chark/clue/test/web/dist;
}
location /clue-web {
alias /iflytek/chark/clue/web/dist;
}
//管理端页面
location /clue-admin {
alias /iflytek/chark/clue/admin/dist;
}
}
配置文件结束后需要编写两个环境的jar包启动脚本
start.sh
#!/bin/bash
nohup java -jar business-clue.jar --spring.profiles.active=prod >> clue.log 2>&1 &
# 启动jar 沉睡60S 再切换配置文件
sleep 60 && cd /iflytek/chark/nginx/nginx/conf
# 替换
sed -i "s/include chark-other.conf;/#include nginx-other.conf;/" nginx.conf
# 替换后重启
sed -i "s/#include chark.conf;/include nginx1.conf;/" nginx.conf && ./../sbin/nginx -s reload
tailf /iflytek/chark/clue/java/clue.log
other_start.sh
#!/bin/bash
nohup java -jar business-clue-other.jar --spring.profiles.active=other >> clue-other.log 2>&1 &
sleep 60 && cd /iflytek/chark/nginx/nginx/conf
sed -i "s/include chark.conf;/#include chark.conf;/" nginx.conf
sed -i "s/#include chark-other.conf;/include chark-other.conf;/" nginx.conf && ./../sbin/nginx -s reload
tail -f /iflytek/chark/clue/java/clue-other.log
结束!