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;
}
}

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值