注意: 建议使用的时候把注释全部去掉
adminv2.jianliwu.com.conf(页面和端口)
server {
listen 80;
server_name adminv2.jianliwu.com;
access_log /etc/nginx/logs/access.log combined;
index index.html index.jsp index.php; # 如果我们访问根目录,他去找哪一个默认文件
location = / { # 如果访问根路径,adminv2.jianliwu.com, 就去root代表的目录下去找
root /product/front/mmall/dist;
index index.html;
}
location ~ .*\.html$ { # 访问了一个index.html, $表示以...为结尾
root /product/front/mmall/dist;
index index.html;
}
location ~ .*\.do$ { # 访问接口的时候, 把请求转到其他服务器上, 也就是接口服务器
proxy_pass http://admintest.happymmall.com;
}
# 它和第一个=/不同,第一个类似exact精确匹配; 但是它类似错误页,如果都匹配不到就用它, 有了它后可以用BrowserRouter
location / {
try_files $uri $uri/ /index.html;
}
}
s.jianliwu.com.conf(静态资源)
server {
listen 80;
server_name s.jianliwu.com;
access_log /etc/nginx/logs/access.log combined;
index index.html index.jsp index.php;
# 静态文件不想让用户通过http访问, 拒绝
location ~ /mmall/dist/view/* {
deny all;
}
location / {
root /product/front/;
add_header Access-Control-Allow-Origin '*';
}
}