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

打印 上一主题 下一主题

主题 902|帖子 902|积分 2706

1.打包前端Vue文件,在项目的Bin文件夹中有个build.bat 点击运行

2.将生成的dist文件夹移动到长途工具上,自选一个你可以记住的位置。我用的是mobieXterm
3.打开edit侧边栏的maven,你要将ruoyi-admin打包,但是你直接打包可能会显示错误,找不到依赖,点击父目录ruoyi中的install,要先下载依赖,再点击ruoyi-admin中的打包,即可成功。打包后的jar文件存在了项目下的target下。

4.然后拖入到长途连接你指定的文件夹中。
5.配置文件,application-druid.yml 配置你的数据库为你的云服务器上的数据库。

将localhost 换成你的云服务ip地点
6.进入阿里云服务器安全组,设置开放端标语(你的若依端标语)
7.防火墙端口开启(我是把防火墙整个全关了,很不安全,以是可以设置一下)
8.进入文件夹中输入下令 java -jar +打包的文件名(此时应该看到网页显示你的后端启动)
9.输入nohup java -jar +文件名 这个是挂起的操纵,不消开云服务器也能跑。
10.启动下好的nginx
11.配置nginx(最难的一步)
  1. #user  root;
  2. worker_processes  1;
  3. #error_log  logs/error.log;
  4. #error_log  logs/error.log  notice;
  5. #error_log  logs/error.log  info;
  6. #pid        logs/nginx.pid;
  7. events {
  8.     worker_connections  1024;
  9. }
  10. http {
  11.     include       mime.types;
  12.     default_type  application/octet-stream;
  13.     #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
  14.     #                  '$status $body_bytes_sent "$http_referer" '
  15.     #                  '"$http_user_agent" "$http_x_forwarded_for"';
  16.     #access_log  logs/access.log  main;
  17.     sendfile        on;
  18.     #tcp_nopush     on;
  19.     #keepalive_timeout  0;
  20.     keepalive_timeout  65;
  21.     proxy_connect_timeout 300;
  22.     proxy_send_timeout 300;
  23.     proxy_read_timeout 300;
  24.     #gzip  on;
  25.     server {
  26.         listen       80;
  27.         server_name  8.130.67.151;#(你的服务器地址)
  28.         #charset koi8-r;
  29.         #access_log  logs/host.access.log  main;
  30.         location / {
  31.             root   /usr/local/project/dist;#(你的dist文件地址)
  32.             index  index.html index.htm;
  33.             try_files $uri $uri/ /index.html;
  34.         }
  35.         location ~* \.(jpg|jpeg|png|gif|css|js|ico)$ {#(处理静态资源)
  36.             root   /usr/local/project/dist;  # Vue 项目打包后的 dist 目录路径
  37.             expires 30d;
  38.         }  
  39.         #error_page  404 /404.html;
  40.         # redirect server error pages to the static page /50x.html
  41.         #
  42.         error_page   500 502 503 504  /50x.html;
  43.         location = /50x.html {
  44.             root   html;
  45.         }
  46.         # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  47.         #
  48.         #location ~ \.php$ {
  49.         #    proxy_pass   http://127.0.0.1;
  50.         #}
  51.         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  52.         #
  53.         #location ~ \.php$ {
  54.         #    root           html;
  55.         #    fastcgi_pass   127.0.0.1:9000;
  56.         #    fastcgi_index  index.php;
  57.         #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
  58.         #    include        fastcgi_params;
  59.         #}
  60.         # deny access to .htaccess files, if Apache's document root
  61.         # concurs with nginx's one
  62.         #
  63.         #location ~ /\.ht {
  64.         #    deny  all;
  65.         #}
  66.         location /prod-api/ {# 在网页上F12会发现有这个,请求地址的代理配置,所以一定要加上
  67.         proxy_pass http://localhost:8082/;  # 替换成前端vite.config.js中targetI地址:后端应用的端口.(设置成云服务器的IP地址,就会有验证码出不来的问题)
复制代码

  1. # 设置请求头,以保留访问客户端的真实IP地址
  2.             proxy_set_header Host $host;
  3.             proxy_set_header X-Real-IP $remote_addr;
  4.             proxy_set_header remote-host $remote_addr;
  5.             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  6.             add_header 'access-control-allow-origin' '*';
  7.             add_header 'access-control-allow-credentials' 'true';
  8.             add_header 'access-control-allow-methods' '*';
  9.         }
  10.     }
  11.     # another virtual host using mix of IP-, name-, and port-based configuration
  12.     #
  13.     #server {
  14.     #    listen       8000;
  15.     #    listen       somename:8080;
  16.     #    server_name  somename  alias  another.alias;
  17.     #    location / {
  18.     #        root   html;
  19.     #        index  index.html index.htm;
  20.     #    }
  21.     #}
  22.     # HTTPS server
  23.     #
  24.     #server {
  25.     #    listen       443 ssl;
  26.     #    server_name  localhost;
  27.     #    ssl_certificate      cert.pem;
  28.     #    ssl_certificate_key  cert.key;
  29.     #    ssl_session_cache    shared:SSL:1m;
  30.     #    ssl_session_timeout  5m;
  31.     #    ssl_ciphers  HIGH:!aNULL:!MD5;
  32.     #    ssl_prefer_server_ciphers  on;
  33.     #    location / {
  34.     #        root   html;
  35.     #        index  index.html index.htm;
  36.     #    }
  37.     #}
  38. }
复制代码

记住配置完肯定要革新一次。
下面是阿里云安全组配置。

这下就应该差不多喽

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

正序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

慢吞云雾缓吐愁

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表