赞
踩
安装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/
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;
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。