Nginx中部署多个前端项目

1,准备前端项目

tlias系统的前端资源

外卖项目的前端资源

2,nginx里面的html文件夹中新建,tlias和sky两个文件夹。

切记这是在nginx/html下创建的

bash 复制代码
mkdir sky
mkdir tlias

把tlias和sky的资源都放到对应的文件夹中

3,编辑配置nginx.conf文件

第一个server监听88端口,

第二个server监听 81端口

复制代码
#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;

    map $http_upgrade $connection_upgrade{
        default upgrade;
        '' close;
    }


    server {
        listen       88;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html/sky;
            index  index.html index.htm;
        }


        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # ▒▒▒▒▒▒▒,▒▒▒▒▒▒▒˷▒▒͵▒▒▒▒▒
        location /api/ {
            proxy_pass   http://localhost:8080/admin/;
        }

        # ▒▒▒▒▒▒▒,▒▒▒▒▒û▒▒˷▒▒͵▒▒▒▒▒
        location /user/ {
            proxy_pass   http://localhost:8080/user/;
        }

        # WebSocket
        location /ws/ {
            proxy_pass   http://localhost:8080/ws/;
            proxy_http_version 1.1;
            proxy_read_timeout 3600s;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "$connection_upgrade";
        }

    }


     server {
        listen       81;
        server_name  localhost;
        client_max_body_size 10m;

        location / {
            root   html/tlias;
            index  index.html index.htm;
        }

        location ^~ /api/ {
            rewrite ^/api/(.*)$ /$1 break;
            proxy_pass http://localhost:8081;
        }
    }


}

4,重启nginx

注意!!! 我下面列举的 启动,停止,重启。都是在 Nginx的sbin目录下执行的

一般我们改了 conf文件之后就会重启下nginx

复制代码
./nginx -s reload

补充下nginx的常用命令

启动命令
复制代码
./nginx

查看下进程是否起来了

关闭命令
复制代码
./nginx -s stop

再看看是否还有nginx进程在运行

5,看效果:

相关推荐
程序员鱼皮7 分钟前
Claude Opus 5 全新发布,7 大项目实测,夯还是拉?半价吊打 Fable 5?
前端·后端·ai编程
极简前端打杂工13 分钟前
从0到1搭建通用低代码平台(-)— 表单设计器
前端·全栈
吃饺子不吃馅14 分钟前
那就和前端好好道个别吧
前端
_瑞15 分钟前
试图教会你用 Xcode Instruments
前端·ios·xcode
Shell运维手记25 分钟前
ARP 协议超详细讲解(适合网工考试 / 运维理解)
运维·网络·网络协议·智能路由器
海带紫菜菠萝汤1 小时前
WebCodecs API 实战:浏览器原生视频编解码的原理与性能测试
前端·javascript·音视频·视频编解码
西安景驰电子1 小时前
PCIe 授时卡原理及应用
运维·服务器·windows·单片机·嵌入式硬件·fpga开发
一位正在转型AI全栈的前端工程师1 小时前
AI 全栈学习之旅 - Week2:从零搭建一个可部署的 AI 聊天应用
前端
aixingpan1 小时前
aixingpan.cn API开发文档:api_docs_trichart_natal_solararc_transit2接口指南
前端·php
Ayayoyo2 小时前
公平随机转盘的前端实现:Web Crypto API、拒绝采样与加权抽取
前端