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

news/2024/7/23 19:12:05 标签: nginx, linux, 运维, java, jvm

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

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

一、前端打包

在这里插入图片描述

java">npm run build

二、后端打包

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

三、Linux部署

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

安装wgte

java">yum install wget

下载nginx

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

解压压缩文件

java">tar -zxvf nginx-1.21.6.tar.gz

进入nginx文件夹

java">cd nginx-1.21.6

配置

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

编译和安装

java">编译: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:
java">nohup java -jar -Dspring.profiles.active=prod wx-api.jar &

停止:

java">kill -9 进程号
  1. 配置Nginx
    nginx.conf:
java">
#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.niftyadmin.cn/n/5024222.html

相关文章

HTML的学习 Day01

《网页设计与制作》是web前端开发技术中静态网页中的内容,主要包括html、css、js中的静态内容部分,是专业基础课程。 随着5G时代的到来,人工智能与物联网结合行业的飞速发展,更多的互联网的崛起。这肯定就比如伴随着对移动互联网…

线性代数的本质(八)——内积空间

文章目录 内积空间内积空间正交矩阵与正交变换正交投影施密特正交化实对称矩阵的对角化 内积空间 内积空间 三维几何空间是线性空间的一个重要例子,如果分析一下三维几何空间,我们就会发现它还具有一般线性空间不具备的重要性质:三维几何空…

[NLP] LLM---训练一个中文LLama2的步骤

一 数据集 【Awesome-Chinese-LLM中文数据集】 【awesome-instruction-dataset】【awesome-instruction-datasets】【LLaMA-Efficient-Tuning-数据集】Wiki中文百科(25w词条)wikipedia-cn-20230720-filteredBaiduBaiKe(563w词条) …

springboot对接postgres

安装postgres 注意:下述链接方式会自动创建数据库steven_russell,若需要创建其他数据库,可以手动执行命令创建数据库 docker run --name postgres \ -p 5432:5432 \ -e POSTGRES_USERsteven_russell \ -e POSTGRES_PASSWORD123456 \ -itd --privilegedtrue postgre…

2023年9月13日

1> 将之前定义的栈类和队列类都实现成模板类 栈 #include <iostream>using namespace std;template <class T> class Stack { private:T data[8];int top;public://构造函数Stack(){top-1;}//构析函数~Stack(){}//判空bool stack_empty(Stack *p){if(p->to…

CRM赢得不同类型客户的策略:从设置正确的目标开始

随着企业对客户关系管理的需求的增加&#xff0c;越来越多的公司选择使用CRM系统来提高自己的业务。但是&#xff0c;如何赢得不同类型的客户呢&#xff1f;总的来说&#xff0c;有几个关键的因素需要考虑。1.设置正确的目标&#xff0c;2.了解客户的需求&#xff0c;3.市场活动…

【配电变电站的最佳位置和容量】基于遗传算法的最优配电变电站放置(Matlab代码实现)

&#x1f4a5;&#x1f4a5;&#x1f49e;&#x1f49e;欢迎来到本博客❤️❤️&#x1f4a5;&#x1f4a5; &#x1f3c6;博主优势&#xff1a;&#x1f31e;&#x1f31e;&#x1f31e;博客内容尽量做到思维缜密&#xff0c;逻辑清晰&#xff0c;为了方便读者。 ⛳️座右铭&a…

滚动条设置

不同浏览器滚动条样式及滚动定位 是否可以滚动 overflow&#xff1a;scroll overflow&#xff1a;autooverflow:scroll – 只有超出了盒子才会有滚动条 overflow:auto – 一直有滚动的盒子&#xff0c;只是超出了盒子才会出现滚动条滑块&#xff0c;可以滚动 谷歌浏览器滚动…