侧边栏壁纸
博主头像
SeaDream乄造梦

Dream,Don't stop a day of hard and don't give up a little hope。 ——不停止一日努力&&不放弃一点希望。

  • 累计撰写 39 篇文章
  • 累计创建 20 个标签
  • 累计收到 13 条评论

目 录CONTENT

文章目录

nginx前后端分离项目部署—配置过程记录

SeaDream乄造梦
2022-09-12 / 0 评论 / 0 点赞 / 962 阅读 / 4,332 字
温馨提示:
亲爱的,如果觉得博主很有趣就留下你的足迹,并收藏下链接在走叭

此为项目部署记录,便于再次部署项目前来参考。
看此博文前,建议没有基础的小伙伴先看此文章:nginx、linux项目部署环境搭建完整过程

mysql

docker run --name mysql_electronic_registration --restart=always -v /aaa/xxx/mysql/conf:/etc/mysql/my.conf -v /aaa/xxx/mysql/data:/var/lib/mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password -e TZ=Asia/Shanghai  -e LANG="C.UTF-8"   -d mysql:8.0.29-oracle

参数解释
解决不能输入中文
-e LANG="C.UTF-8"
--restart=always
always 容器退出时总是重启
-e MYSQL_ROOT_PASSWORD
设置myslq容器登录密码
-e TZ=
设置时区
-d
后台运行
-e LANG="C.UTF-8"
容器内部不能输入中文解决

mysql.cnf

[mysqld]
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
datadir         = /var/lib/mysql
#log-error      = /var/log/mysql/error.log
# By default we only accept connections from localhost
#bind-address   = 127.0.0.1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
character_set_server=utf8
init_connect='SET NAMES utf8'
max_allowed_packet = 20M

[mysql]
default-character-set = utf8

[mysql.server]
default-character-set = utf8

[mysqld_safe]
default-character-set = utf8

[client]
default-character-set = utf8

redis

docker run --name redis6 -p 6379:6379  -v /aaa/bbb/redis6/data:/data    -v /aaa/bbb/redis6/redis-conf:/usr/local/etc/redis    -d --restart=always  redis:6.2.7   redis-server   --appendonly yes  --requirepass "password"

-p 表示端口映射
-v 表示宿主机和容器之间的文件映射
--name 表示docker容器的名字
-d 表示在后台运行,并且打印容易id
--restart=always 表示可以自启动 redis:latest 启动容器的镜像
--appendonly yes 表示redis持久化
--requirepass 表示设置的密码

nginx

docker run --name nginx_xxx -p 8005:80 -v /aaa/xxx:/aaa/xxx  -v /aaa/xxx/nginx/conf.d:/etc/nginx/conf.d -v /aaa/xxx/nginx/log/nginx:/var/log/nginx:rw -d nginx:latest

nginx.conf

瑞吉

upstream myserver3{
    server 172.17.0.1:8080;
}

server{
    listen 80;
    #域名,根据实际情况修改
    server_name localhost;
    client_max_body_size 20m;
    #后台,根据实际情况修改
    access_log /var/log/nginx/host.access.log main;

    location / {
        root  /aaa/xxx/xxx_web/dist/;
        try_files $uri $uri/ /index.html?s=$uri&$args;
        index index.html;
    }


        #反向代理配置
     location ^~ /api/ {
     	 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 X-Forwarded-Proto $scheme;
   		 rewrite ^/api/(.*)$ /$1 break;
   		 proxy_pass http://myserver3;
   		 index  index.html index.htm;
	}

}

陪护

#参考博客:https://blog.csdn.net/qq_42937522/article/details/108179441

#peihu-server
upstream myserver3{
    server 172.17.0.1:8004;
}


server{
    listen 80;
    #域名,根据实际情况修改
    server_name localhost;
    client_max_body_size 20m;

    access_log /var/log/nginx/host.access.log main;

    #后台,根据实际情况修改
    
    location  ^~ /h5/ {
        alias  /aaa/bbb/xxx/xxx_h5/dist/;
        try_files $uri $uri/ /h5/index.html?s=$uri&$args;
        index index.html index.htm index.php;
    }

    location / {
        root  /aaa/bbb/xxx/xxx_web/dist/;
        try_files $uri $uri/ /index.html?s=$uri&$args;
        index index.html index.htm index.php;
    }


    #后端
    location /h5/undefined/api {
       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 X-Forwarded-Proto $scheme;
       proxy_pass http://myserver3/api;
       index  index.html index.htm;
       rewrite "^/h5/undefined/(.*)$" /$1 break;
    }
    location  /api {
	 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 X-Forwarded-Proto $scheme;
	 proxy_pass http://myserver3;
	 index  index.html index.htm;
    }  

}

需要域名和静态地址的配置

upstream myserver3{
    server 172.0.0.1:8096;
}

server{
    listen 80;
    #域名,根据实际情况修改
    server_name aaa.bbb.fun;
    client_max_body_size 20m;
    rewrite ^(.*)$ https://aaa.bbb.fun;
}

server {
    listen 443 ssl;
    server_name aaa.bbb.fun;
    client_max_body_size 20m;
 
    access_log /var/log/nginx/recruitment.access.log main;
 
   
        
    ssl_certificate  /etc/nginx/cert/xxx.pem;
    ssl_certificate_key  /etc/nginx/cert/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 / {
        root  /data/xxx/er_web/dist/;
        try_files $uri $uri/ /index.html?s=$uri&$args;
        index index.html;
    }

    location /mp/ {
        alias  /data/xxx/MP/;
    }

    location /api/static/img/ {
        alias  /data/xxx/photo/;
    }



        #反向代理配
    location ^~ /api/ {
     	 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 X-Forwarded-Proto $scheme;
   		 rewrite ^/api/(.*)$ /$1 break;
   		 proxy_pass http://myserver3;
   		 index  index.html index.htm;
    }
}

后端服务启动

nohup java -server  -XX:-DisableExplicitGC -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -jar 
/aaa/bbb/ccc/ddd/xxx-1.0.0-RELEASE.jar 
--spring.profiles.active=dev --server.port=8001 > start.log 2>&1 &
nohup java -jar xxx-1.0-SNAPSHOT.jar &> start.log &
0

评论区