如何使用二级目录
本文介绍,卷王问卷系统,如何添加二级目录。
代码修改
二级目录版本分支已单独推送到源码仓库。
默认的二级目录名称是 /survey
。如需改为其他名称,只需要调整 .umirc.ts
中的 publicPath 和 base。
nginx 配置
正式部署的 nginx 配置文件如下,重点参见下面配置文件 ① 和 ② 两处修改
server
{
listen 80;
index index.php index.html index.htm default.php default.htm default.html;
location ^~ /survey {
alias /usr/local/html; # ① 修改此处路径为静态文件的绝对路径
index index.html;
try_files $uri $uri/ /survey/index.html; # ② 默认的二级目录名称是 /survey,如果为其他的需要修改此处
}
# 二维码代理
location /survey/captcha {
# 给端口 1991 改成安装后端时的端口
proxy_pass http://localhost:1991/captcha;
set_real_ip_from 0.0.0.0/0;
real_ip_header X-Forwarded-For;
real_ip_recursive on;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 30m;
proxy_http_version 1.1;
proxy_set_header Connection close;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_send_timeout 1800;
proxy_read_timeout 1800;
proxy_connect_timeout 1800;
}
# 后端接口代理
location /survey/admin-api {
# 给端口 1991 改成安装后端时的端口
proxy_pass http://localhost:1991/admin-api;
set_real_ip_from 0.0.0.0/0;
real_ip_header X-Forwarded-For;
real_ip_recursive on;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 30m;
proxy_http_version 1.1;
proxy_set_header Connection close;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_send_timeout 1800;
proxy_read_timeout 1800;
proxy_connect_timeout 1800;
}
}
常见问题
配置转发
使用场景,只允许外网访问答卷页面,管理页面只允许内网访问,外网和内网是不同的 nginx,可以在外网 nginx 配置代理转发到内网 nginx,配置如下
server{
listen 80;
server_name surveyking.cn;
# 代理答卷页面
location ^~ /survey/s {
proxy_pass http://10.24.10.24:80/survey/s;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# 代理后端接口请求
location ^~ /survey/admin-api {
proxy_pass http://10.24.10.24:80/survey/admin-api;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# 代理前端静态文件
location ~ ^/survey/(.+\.(js|css))$ {
proxy_pass http://10.24.10.24:80/survey/$1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}