栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

nginx部署项目

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

nginx部署项目

​
安装nginx部分参考:(本人已验证,完全可行)
https://www.cnblogs.com/EasonJim/p/7806879.html

单一项目部署

1、/usr/local/nginx/conf/nginx.conf中添加项目地址

server {
listen 80;
server_name localhost;
location / {
root /usr/local/web/dist;
index index.html index.htm;
}
# location
# root: 将接收到的资源根据/usr/local/web/dist文件夹去查找资源
# index: 默认去上述路径中找到index.html或者index.htm
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}

2、将dist文件夹上传到上面指定路径
/usr/local/nginx/html
之后启动nginx
root@ubuntu:/usr/local/nginx/sbin# nginx
3、浏览器访问:
浏览器访问服务器地址,因为配置的是80端口,所以默认不用加端口号
http://localhost/

如果是多项目,同一端口,通过location 区分

http://localhost/#/login
http://localhost/boke/#/login
在/usr/local/web/目录下新建dist2
项目放到该目录下,并修改 /usr/local/nginx/conf/nginx.conf,
在原有的server 节点下添加 并列的 location节点,注意 root 替换成 alias

location / {
root /usr/local/web/dist;
index index.html index.htm;
}
location /boke {
alias /usr/local/web/dist2;
index index.html index.htm;
}

如果是多项目多端口

http://localhost/#/login

http://localhost:8888/#/login
增加并列的server节点,并上传项目到 /usr/local/web/dist2;
server {
listen 8888;
server_name localhost;
location / {
root /usr/local/web/dist2;
index index.html;
}
}

多域名访问(待验证)

server {
listen 8888;
server_name mywentest;

    location / { 
            root /usr/local/web/dist2;
            index index.html;
    }

}

反向代理

访问:http://localhost,则实际访问 http://192.168.116.1:8091
server {
listen 80;
server_name localhost;
location / {
#本地服務
#root /usr/local/web/dist;
#index index.html index.htm;
#反向代理
proxy_pass http://192.168.116.1:8091;
}
}

负载均衡
方式1、不同服务器做均衡

访问:http://localhost 实际访问 192.168.116.129:8092或者192.168.116.1:8091
weight权重,值越大访问的占比越高
server同级添加服务器地址
upstream proxy_http {
server 192.168.116.129:8092 weight=1;
server 192.168.116.1:8091 weight=1;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://proxy_http;
}
}
方式2、统一服务器不同的端口做均衡
访问:http://localhost:80 实际访问 实际访问 8091、8092、8093端口,weight 权重
upstream proxy_http {
server 192.168.116.1:8091 weight=1;
server 192.168.116.1:8092 weight=1;
server 192.168.116.1:8093 weight=1;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://proxy_http;
}
server {
listen 8091;
server_name localhost;
location / {
root /usr/local/web/dist;
index index.html;
}
server {
listen 8092;
server_name localhost;
location / {
root /usr/local/web/dist2;
index index.html;
}
server {
listen 8093;
server_name localhost;
location / {
root /usr/local/web/dist3;
index index.html;
}
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/962671.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号