若依部署项目到服务器

目录

一、环境配置

redis

nginx(宿主机|dokcer)

1.宿主机

2.docker

二、打包jar包

0.查看后端配置

1.打包后端

2.打包前端

三、启动

1.后端

2.前端

四、以上部署常见命令/错误


一、环境配置

之前的课都配过,先看看自己配了没

看看启动了啥 docker ps

redis

见上 redis启用过了

nginx(宿主机|dokcer)

1.宿主机

强制启动,查看是否启动成功,没有就是端口占用,关了就行

如果有以下,则证明是docker里边的,要么见2,要么停了dokcer再1

2.docker

复制代码
docker run -d --name nginx\
   -p 80:80 \
   --restart=always \
   -v /opt/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
   -v /opt/nginx/html/dist:/usr/share/nginx/html \
 nginx:1.25.0

二、打包jar包

0.查看后端配置

1.打包后端

打包之后的在这里👇

2.打包前端

三、启动

1.后端

复制代码
切换到自己的jar包放置路径
java -jar ruoyi-admin.jar

这样就启动成功后端了

访问路径 公网地址:8080

2.前端

把打包好的dist复制到宿主机上,注意自己的路径

更改这里边的conf

主要更改地方和源码在👇

复制代码
#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  82.157.170.39 localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /opt/nginx/html/dist;
            try_files $uri $uri/ /index.html;
            index  index.html index.htm;
        }
        location /prod-api/ {
			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_pass http://172.17.0.1:8080/;
		}

        #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   /opt/nginx/html/dist;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

运行地址 公网地址 出来验证码就算对了

四、以上部署常见命令/错误

复制代码
#查看端口是否被占用
sudo netstat -tulnp | grep :80

#查看进程是否启动
ps aux | grep nginx

#进入容器内部
docker exec -it nginx /bin/bash

#查看容器内nginx.conf文件内容
cat etc/nginx/nginx.conf


#关于防火墙
systemctl start firewalld 开启防火墙
 
systemctl restart firewalld 重启防火墙
 
systemctl status firewalld 查看防火墙状态
 
systemctl disable firewalld 开机自动不启动防火墙
 
firewall-cmd --permanent --add-port=端口/tcp 设置防火墙放
行端口,此操作需要重启防火墙生效
 
# 重新加载防火墙规则
firewall-cmd --reload
 
# 详细查看放行端口
firewall-cmd --list-all

后端没什么大问题,主要是前端

如果有404 500 页面无法访问错误,就是nginx.conf配置有错,或者nginx启动有错