Nginx部署前后端分离项目(Linux)

news/2024/4/27 5:15:16

Nginx代理前端页面、后端接口

  • 一、前端打包
  • 二、后端打包
  • 三、Linux部署
  • Nginx启动、暂停、重启
  • 服务器部署文件地址:

一、前端打包

在这里插入图片描述

npm run build

二、后端打包

通过Maven 使用package打包
在这里插入图片描述

三、Linux部署

  1. 安装Nginx
    安装环境
yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel

安装wgte

yum install wget

下载nginx

wget https://nginx.org/download/nginx-1.21.6.tar.gz

解压压缩文件

tar -zxvf nginx-1.21.6.tar.gz

进入nginx文件夹

cd nginx-1.21.6

配置

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

编译和安装

编译:make
安装:make install

Nginx启动、暂停、重启

启动
/usr/local/nginx/sbin/nginx
重启
/usr/local/nginx/sbin/nginx -s reload
如果更改了配置文件建议使用这个方式重新启动
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
停止服务
/usr/local/nginx/sbin/nginx -s stop

  1. 安装java环境(用于启动jar)
    安装地址:https://blog.csdn.net/A_yonga/article/details/125526307
    启动jar:
nohup java -jar -Dspring.profiles.active=prod wx-api.jar &

停止:

kill -9 进程号
  1. 配置Nginx
    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;server {listen       80;server_name  localhost;#charset koi8-r;#access_log  logs/host.access.log  main;location / {root   /data/wx/dist;  // 前端文件地址index  index.html index.htm;}location /wx {proxy_pass http://127.0.0.1:8080/wx;// 后端接口地址及端口}#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;#}}# 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  如不需要https 则全用#注释#server {listen       443 ssl;server_name  localhost;ssl_certificate      /application/nginx-wx/ssl/cacert.pem;ssl_certificate_key  /application/nginx-wx/ssl/privkey.pem;ssl_session_cache    shared:SSL:1m;ssl_session_timeout  5m;ssl_ciphers  HIGH:!aNULL:!MD5;ssl_prefer_server_ciphers  on;location / {root   /data/wx/dist; index  index.html index.htm;}location /wx {proxy_pass http://127.0.0.1:8080/wx;}}}
  1. 需要开启Https生成ssl临时证书
    https://blog.csdn.net/who7708/article/details/104565369

服务器部署文件地址:

前台文件:/data/wx/dist
后台文件:/data/wx/wx-api.jar
nginx文件:/usr/local/nginx/

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.tangninghui.cn.cn/item-26.htm

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈,一经查实,立即删除!

相关文章

iframe 实现跨域,两页面之间的通信

一、 背景 一个项目为vue2,一个项目为vue3,两个不同的项目实现iframe嵌入,并实现通信 二、方案 iframe跨域时,iframe组件之间常用的通信,主要是H5的possmessage方法 三、案例代码 父页面-vue2(端口号为…

web安全之XSS攻击

什么是XSS攻击 XSS(Cross-Site Scripting)又称跨站脚本,XSS的重点不在于跨站点,而是在于脚本的执行。XSS是一种经常出现在 Web 应用程序中的计算机安全漏洞,是由于 Web 应用程序对用户的输入过滤不足而产生的。 常见…

Java笔记:Java线程Dump分析

1 Thread Dump介绍 1.1 什么是Thread Dump Thread Dump是非常有用的诊断Java应用问题的工具。每一个Java虚拟机都有及时生成所有线程在某一点状态的thread-dump的能力,虽然各个 Java虚拟机打印的thread dump略有不同,但是 大多都提供了当前活动线程的快…

230. 二叉搜索树中第K小的元素 Python

文章目录 一、题目描述示例 1示例 2 二、代码三、解题思路 一、题目描述 给定一个二叉搜索树的根节点 root ,和一个整数 k ,请你设计一个算法查找其中第 k 个最小元素(从 1 开始计数)。 示例 1 输入:root [3,1,4,nu…

荣誉丨“Qspace|轻空间”荣获“盐城市零碳空间工程技术研究中心”称号

近日,盐城市科学技术局公布了《2023年度盐城市工程技术研究中心认定名单》,轻空间(江苏)膜科技有限公司荣誉入选。 工程技术研究中心是指主要依托城市综合实力和创新能力较强的企业、高校或科研院所,具有较完备的工程技术综合配套…

竞赛选题 基于机器视觉的火车票识别系统

文章目录 0 前言1 课题意义课题难点: 2 实现方法2.1 图像预处理2.2 字符分割2.3 字符识别部分实现代码 3 实现效果最后 0 前言 🔥 优质竞赛项目系列,今天要分享的是 基于机器视觉的火车票识别系统 该项目较为新颖,适合作为竞赛…