当前位置:   article > 正文

nginx部署项目

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;
    }
  • 1
  • 2
  • 3
  • 4

}

反向代理

访问: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、不同服务器做均衡
  • 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;
}
}

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/232369
推荐阅读
相关标签
  

闽ICP备14008679号