Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] nginx反代-次级目录配置以访问静态文件 #359

Open
4 tasks done
moondigi opened this issue Jan 15, 2023 · 5 comments
Open
4 tasks done

[Feature] nginx反代-次级目录配置以访问静态文件 #359

moondigi opened this issue Jan 15, 2023 · 5 comments
Labels
enhancement New feature or request

Comments

@moondigi
Copy link

Verify steps

  • Tracker 我已经在 Issue Tracker 中找过我要提出的问题
  • Need 当前 QianDao 框架并不包含该功能特性或者还不完善
  • Framework 这是 QianDao 框架应包含的特性,并非模板特性
  • Meaningful 我提交的不是无意义的 催促更新或修复 请求

Describe the Feature

当我用nginx反代qiandao到次级目录的时候,因为js和css等资源地址为根目录导致需要写多条nginx规则

Describe the solution

想以http://域名/qiandao,来访问使用
以下为nginx反代规则,希望项目的资源都是相对目录方便反代,或者增加config.py的次级目录设置
location /qiandao/ { proxy_pass http://127.0.0.1:8923/; }

Describe alternatives

No response

Additional context

No response

@moondigi moondigi added the enhancement New feature or request label Jan 15, 2023
@leic4u
Copy link
Contributor

leic4u commented Apr 29, 2023

+1,之前试过这样反代没成功,暂时只能以三级域名的方式反代了。

@a76yyyy a76yyyy added this to QD Jun 10, 2023
@a76yyyy a76yyyy moved this to 暂无计划 in QD Jun 10, 2023
@a76yyyy a76yyyy moved this from 暂无计划 to Todo in QD Jun 10, 2023
a76yyyy added a commit that referenced this issue Jun 14, 2023
Add `STATIC_URL_PREFIX` Environment Variables
@a76yyyy
Copy link
Contributor

a76yyyy commented Jun 14, 2023

@moondigi @leic4u 现在可以通过设置环境变量 STATIC_URL_PREFIX 或者修改配置文件来设置静态文件路径前缀了

请通过更新至Dev版或者更新最新源码, 以使用相关功能, 如有问题请及时反馈

PS: 跨版本更新或更新源码 请务必备份数据库

@a76yyyy a76yyyy changed the title [Feature] nginx反代 [Feature] nginx反代-次级目录配置以访问静态文件 Jun 14, 2023
@github-project-automation github-project-automation bot moved this from Todo to Done in QD Jun 14, 2023
@xq330
Copy link

xq330 commented Aug 14, 2023

设置STATIC_URL_PREFIX后还是无法实现二级反代
目前STATIC_URL_PREFIX设置为/qdstatic/
ngnix配置如下

location ^~/qd/ {
        proxy_pass http://127.0.0.1:8923;
        proxy_http_version 1.1;
        proxy_read_timeout 300;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Real-PORT $remote_port;
		rewrite "^/qd/(.*)$" /$1 break;
}
location ^~/qdstatic/ {
        proxy_pass http://127.0.0.1:8923;
        proxy_http_version 1.1;
        proxy_read_timeout 300;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Real-PORT $remote_port;
}

123

例如首页: https://qiandao.com/qd/
页面所有的请求地址还是https://qiandao.com/xxx,例如登录页地址为https://qiandao.com/login,必须为https://qiandao.com/qd/login才能正常显示。config.py 没有配置api次级目录的地方。目前还是没法实现二级反代。

@moondigi
Copy link
Author

之前没有验证更改就关闭问题了,今天重新尝试用子目录部署的时候发现正如楼上所说,不少页面的url并没有应用STATIC_URL_PREFIX设置的目录

最终实现的效果应该是,整个项目的根应该为设置的子目录,当设置了子目录为/qd/的时候,首页应为http://ip:8923/qd/,登陆页面应为http://ip:8923/qd/login,如此类推

@moondigi moondigi reopened this Dec 10, 2023
@terrytw
Copy link

terrytw commented Oct 1, 2024

供参考
#518 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

No branches or pull requests

5 participants