慢吞云雾缓吐愁 发表于 2024-10-9 12:01:57

若依项目在云服务器上的部署(超详细)

1.打包前端Vue文件,在项目的Bin文件夹中有个build.bat 点击运行
https://i-blog.csdnimg.cn/direct/45b57ee1ab054ee6948d3187f5c6f062.png
2.将生成的dist文件夹移动到长途工具上,自选一个你可以记住的位置。我用的是mobieXterm
3.打开edit侧边栏的maven,你要将ruoyi-admin打包,但是你直接打包可能会显示错误,找不到依赖,点击父目录ruoyi中的install,要先下载依赖,再点击ruoyi-admin中的打包,即可成功。打包后的jar文件存在了项目下的target下。
https://i-blog.csdnimg.cn/direct/726733d382934478b527d1148a531039.png
4.然后拖入到长途连接你指定的文件夹中。
5.配置文件,application-druid.yml 配置你的数据库为你的云服务器上的数据库。
https://i-blog.csdnimg.cn/direct/c91aaf8c3c21436597d9884a360b56be.png
将localhost 换成你的云服务ip地点
6.进入阿里云服务器安全组,设置开放端标语(你的若依端标语)
7.防火墙端口开启(我是把防火墙整个全关了,很不安全,以是可以设置一下)
8.进入文件夹中输入下令 java -jar +打包的文件名(此时应该看到网页显示你的后端启动)
9.输入nohup java -jar +文件名 这个是挂起的操纵,不消开云服务器也能跑。
10.启动下好的nginx
11.配置nginx(最难的一步)
#userroot;
worker_processes1;

#error_loglogs/error.log;
#error_loglogs/error.lognotice;
#error_loglogs/error.loginfo;

#pid      logs/nginx.pid;


events {
    worker_connections1024;
}


http {
    include       mime.types;
    default_typeapplication/octet-stream;

    #log_formatmain'$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_loglogs/access.logmain;

    sendfile      on;
    #tcp_nopush   on;

    #keepalive_timeout0;
    keepalive_timeout65;
    proxy_connect_timeout 300;
    proxy_send_timeout 300;
    proxy_read_timeout 300;

    #gzipon;

    server {
      listen       80;
      server_name8.130.67.151;#(你的服务器地址)

      #charset koi8-r;

      #access_loglogs/host.access.logmain;

      location / {
            root   /usr/local/project/dist;#(你的dist文件地址)
            indexindex.html index.htm;
            try_files $uri $uri/ /index.html;
      }

      location ~* \.(jpg|jpeg|png|gif|css|js|ico)$ {#(处理静态资源)
            root   /usr/local/project/dist;# Vue 项目打包后的 dist 目录路径
            expires 30d;
      }

      #error_page404 /404.html;

      # redirect server error pages to the static page /50x.html
      #
      error_page   500 502 503 504/50x.html;
      location = /50x.html {
            root   html;
      }

      # 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_indexindex.php;
      #    fastcgi_paramSCRIPT_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 {
      #    denyall;
      #}
      location /prod-api/ {# 在网页上F12会发现有这个,请求地址的代理配置,所以一定要加上
      proxy_pass http://localhost:8082/;# 替换成前端vite.config.js中targetI地址:后端应用的端口.(设置成云服务器的IP地址,就会有验证码出不来的问题)
https://i-blog.csdnimg.cn/direct/964df650d9ca41f8af0aa5d7d50e717d.png
# 设置请求头,以保留访问客户端的真实IP地址
            proxy_set_header Host $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;
            add_header 'access-control-allow-origin' '*';
            add_header 'access-control-allow-credentials' 'true';
            add_header 'access-control-allow-methods' '*';
      }
    }

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

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


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_namelocalhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_keycert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout5m;

    #    ssl_ciphersHIGH:!aNULL:!MD5;
    #    ssl_prefer_server_cipherson;

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

}

记住配置完肯定要革新一次。
下面是阿里云安全组配置。
https://i-blog.csdnimg.cn/direct/511dc8d3c76e4549a5bc839e5cc05666.png
这下就应该差不多喽

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: 若依项目在云服务器上的部署(超详细)