ruoyi-vue前后端分类nginx配置

前置条件

  1. 本地安装node.js并配置环境变量(打包vue)
  2. 服务器安装nginx
  3. 服务器安装jdk并配置环境变量
  4. 安装mysql
  5. 安装redis
  6. 参考项目文档本地先系统运维面试题及答案运行一服务器遍再部署到服务器

拉取代码

若依gitee项目地址

git clone https://gitee.com/y_project/RuoYi-Vue.git

修改项目配linux常用命令置并打包

ruoyi-admin修改application.yml中的redis地址,application-druid.yml中的mysql地址

后端打包

mvn clean package

打包后上传到服务器并启动

nohup java -jar ruoyi.jar(根据实际名称修改) &

前端修改配置打包

修改vue.configlinux.js中target为http://127.0.0.1,如果不部署在同一台服务器或者使用域名自行修改

打包系统运维包括哪些内容

npm run build:prod

上传

将打包好的文nginx是什么意思件(dist目录)上传到服务器,我的上传到了/srv/ruoyi目录,解压并修改名称

unzip dist.zip
mv dist web

nginx配置文件修改

使用默认的安装方式,nginx.系统运维工资一般多少conf位于/usr/llinux必学的60个命令ocal/nginx/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;
gzip on;
# server {
# listen 80;
# server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
# location / {
# root html;
# index index.html index.htm;
# }
#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 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_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;
#}
#}
# ruoyi backend
server {
listen 80;
server_name 127.0.0.1;
# 前端服务地址
location / {
root /srv/ruoyi/web;
index index.html;
}
# 后台服务
#location /api/ { 访问192.168.2.13/api/captchaImage 相当于访问127.0.0.1:8080/captchaImage
location /prod-api/ {
proxy_pass http://127.0.0.1:8080/;
}
}
# 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;
# }
#}
}

注意:后台配置location中使用的prod-api是由于前端有个base_url是/prod-api,vue nginx都不是特别熟,暂时不知道什么原因,location配置要注意/,加/不加/请求路径系统运维工程师不一样

重启nginx

/usr/local/nginx/sbin/nginx -s reload

验证

登录


                                            ruoyi-vue前后端分类nginx配置

postman请求

                                            ruoyi-vue前后端分类nginx配置
nginx请求路径
192.168.2.13/prod-api/caplinux重启命令thtml标签属性大全chaImage等同于192.168.2.13:8080/captchaImage