以下是本人通过Docker 部署的Nginx挂载出来的文件目录
先看下 nginx.conf 配置文件内容:如下
ps:当前文件就是安装后的初始内容,无修改。主要关注最后一行 include /etc/nginx/conf.d/*.conf;表示引入其他目录下的.conf配置文件;
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
既然已经定义了可以引入其他路径下的配置文件,那么我们就可以将我们需要部署的多个域名、多个服务的配置分开存放;进入到 conf.d 目录内,如下:
分别看下并解释下配置文件的内容
base.conf 基础配置
server {
# 监听80端口
listen 80;
# 指令定义了服务器块要处理的2个域名 用空格分开
server_name xxxxxx.cn xxxx.xxxx.com;
# 如果访问了server_name 中配置的域名,那么将重定向到 安全域名
# 例如 在浏览器 输入了 xxxx.cn , 那么浏览器将直接将你的访问地址改为https://xxxx.cn
return 301 https://$host$request_uri;
}
stokc.conf 域名一的配置
server {
# listen 80;
# server_name localhost;
# SSL 默认访问端口号为 443
listen 443 ssl;
# 请填写绑定证书的域名
server_name xxxx.cn;
# 请填写证书文件的相对路径或绝对路径
ssl_certificate /etc/nginx/sslSign/xxxx.cn_nginx/xxxx.cn_bundle.crt;
# 请填写私钥文件的相对路径或绝对路径
ssl_certificate_key /etc/nginx/sslSign/xxxx.cn_nginx/xxxx.cn.key;
ssl_session_timeout 5m;
# 请按照以下协议配置
ssl_protocols TLSv1.2 TLSv1.3;
# 请按照以下套件配置,配置加密套件,写法遵循 openssl 标准。
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
location / {
root /home/ruoyi/projects/ruoyi-ui/dist;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
location /prod-api/ {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# 负载均衡服务地址
proxy_pass http://stockserver/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
yunlv.conf 域名二的配置
server {
listen 443 ssl;
server_name xxxx.xxxx.cn;
client_max_body_size 10m;
# 请填写证书文件的相对路径或绝对路径
ssl_certificate /etc/nginx/sslSign/yunlvceshi/xxxx.xxxx.cn_bundle.crt;
# 请填写私钥文件的相对路径或绝对路径
ssl_certificate_key /etc/nginx/sslSign/yunlvceshi/xxxx.xxxx.cn.key;
ssl_session_timeout 5m;
# 请按照以下协议配置
ssl_protocols TLSv1.2 TLSv1.3;
# 请按照以下套件配置,配置加密套件,写法遵循 openssl 标准。
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
location / {
root /home/workData/frontDesk_PC/dist;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
location /api/ {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://yunlvserver/;
}
location /api/wsMsg/anno/OrderMsg/ {
proxy_pass http://yunlvserver/;
proxy_set_header Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# 增加 WebSocket 超时设置
proxy_connect_timeout 12h; # 连接超时时间,设置为1小时
proxy_read_timeout 12h; # 读取超时时间,设置为1小时
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
stream.conf 负载均衡配置
upstream yunlvserver{
server xxx.xxx.xxx.xx:8090;
server xxx.xxx.xxx.xx:8091;
}
upstream stockserver{
server xxx.xxxx.xxx.xx:8081;
server xxx.xxxx.xxx.xx:8082;
}
配置好后重启nginx即可!
over…