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

相关推荐
Lethehong几秒前
算力新标杆:昇腾Atlas 800T NPU实战Llama-2-7b全流程评测与技术解析
运维·服务器·数据库·llama-2-7b·昇腾atlas 800t
wanhengidc3 分钟前
云手机中都运用到了哪些技术
运维·服务器·科技·智能手机·云计算
北慕阳6 分钟前
选择采购单按钮
前端·javascript·数据库
漫漫求7 分钟前
2、Ubuntu 22.04 安装px4 1.14:快速搭建
linux·运维·ubuntu
阑梦清川8 分钟前
计算机网络--关于域名服务器的访问顺序
运维·服务器·计算机网络
华仔啊8 分钟前
Vite 到底能干嘛?为什么 Vue3 官方推荐它做工程化工具?
前端·javascript·vue.js
ZXH012211 分钟前
性能提升60%:性能优化指南
前端·性能优化
卜锦元12 分钟前
docker 部署南大通用 GBase 8sV8.8
运维·数据库·docker·容器·部署·运维开发
赵庆明老师15 分钟前
NET 中深度拷贝一个对象
前端·javascript·ui
小雨下雨的雨16 分钟前
第10篇:Redis监控、运维与故障排查
运维·redis·bootstrap