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,看效果:

相关推荐
我是哈哈hh18 分钟前
【Vue】 核心特性实战解析:computed、watch、条件渲染与列表渲染
前端·javascript·vue.js·前端框架·vue·语法基础
LoveLinuxShell27 分钟前
推荐Linux命令行运维工具: WowKey--实现自动化批量化标准化Linux设备运维
linux·运维·shell·自动化批量化标准化
龙在天43 分钟前
“手速太快,分页翻车?”,前端分页竞态问题,看这一篇就够了
前端
Riesenzahn1 小时前
你使用过css3的:root吗?说说你对它的理解
前端·javascript
Riesenzahn1 小时前
在js中undefined和undeclared有什么区别?
前端·javascript
打野赵怀真1 小时前
平时有经常用到nextTick吗?谈谈你对nextTick的理解。
前端·javascript
LaoZhangAI1 小时前
2025最全Browser Use MCP指南:AI控制浏览器的开源解决方案与API接入全攻略
前端
leopai1 小时前
面试官最喜欢问的:前端怎么自动检测代码更新?
前端·javascript·面试
Fanmeang1 小时前
DHCP Snooping各种场景实验案例
运维·网络·安全·华为·交换机·dhcp·dhcp snooping
学不动学不明白1 小时前
接口错误码监听方法
前端