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

Add sub_path support when dashboard under a subdirectory via nginx reverse proxy. #2219

Closed
ltt1987 opened this issue Nov 19, 2021 · 10 comments
Closed
Labels

Comments

@ltt1987
Copy link

ltt1987 commented Nov 19, 2021

Feature request

当前如需反向代理到apisix dashboard,只能进行根目录的代理,如果指定 http://host/dashboard/ 的二级目录进行代理,代理后dashboard 中的静态资源路径、请求的api接口路径,均为根路径(src="/favicon.png")的引用,期望的地址应该是二级目录(src="/dashboard/favicon.png")地址。

Currently, if you need to reverse proxy to apisix-dashboard, Only support the root directory proxy.

If you set apisix-dashboard under a subdirectory via nginx reverse proxy like http://ip/dashboard/, you will get some errors due to the wrong resource path. E.g: src="/favicon.png" is wrong, src="/dashboard/favicon.png" is correct.

Describe the solution you'd like

建议增加可指定子路径的功能,类似pgAdmin中,通过增加添加自定义Header X-Script-Name 来指定目录。

It is recommended to add the function of specifying sub-path, For example, in pgAdmin, specify the directory by adding a custom Header X-Script-Name.

Additional context

pgAdmin Document:If you wish to host pgAdmin under a subdirectory rather than on the root of the server, you must specify the location and set the X-Script-Name header which tells the pgAdmin container how to rewrite paths:

server {
    listen 80;
    server_name _;

    location /pgadmin4/ {
        proxy_set_header X-Script-Name /pgadmin4;
        proxy_set_header Host $host;
        proxy_pass http://localhost:5050/;
        proxy_redirect off;
    }
}
@juzhiyuan
Copy link
Member

Not sure if it's supported with Apache APISIX 🤔 @tzssangglass could you please have a check?

@juzhiyuan
Copy link
Member

BTW, @ltt1987 I recommend using English here 😄 For we have many contributors and users who speak English and other languages 😄

@ltt1987 ltt1987 changed the title 添加当反向代理dashboard时,自定义子路径的支持 Add sub_path support when dashboard under a subdirectory via nginx reverse proxy. Nov 19, 2021
@ltt1987
Copy link
Author

ltt1987 commented Nov 19, 2021

BTW, @ltt1987 I recommend using English here 😄 For we have many contributors and users who speak English and other languages 😄

Sorry for that, I'm not good at english. I have added English content, but I still keep Chinese in order to avoid wrong description.

@juzhiyuan
Copy link
Member

got it, @bzp2010 would you please take a look?

@tzssangglass
Copy link
Member

we cau use proxy-rewrite plugins to do this, refer to:apache/apisix#3252

@adoal
Copy link

adoal commented Nov 30, 2021

we cau use proxy-rewrite plugins to do this, refer to:apache/apisix#3252

I don't think proxy-rewrite helps, since it only strips the prefix then sends to the backend server, but we also need some mechanism to tell the backend so it will 'know' it should generate anchor URLs under some prefix. Just like SCRIPT_NAME and PATH_INFO in traditional CGI spec.

@tzssangglass
Copy link
Member

since it only strips the prefix then sends to the backend server

APISIX does not modify the url by default.

@bzp2010
Copy link
Contributor

bzp2010 commented Nov 30, 2021

Hi, @ltt1987.

I think the problem is that the compilation product of our dashboard project currently uses absolute paths to load resources, so you need to recompile if you want to proxy dashboard in a subdirectory. These are not directly supported by either the Manager API or the proxy-rewrite plugin in APISIX.

Of course, we can take some measures to improve it, if you are willing to try.

Here are the configures about it.

base: '/',
publicPath: '/',

@juzhiyuan
Copy link
Member

@ltt1987
Copy link
Author

ltt1987 commented Dec 10, 2021

Hi, @ltt1987.

I think the problem is that the compilation product of our dashboard project currently uses absolute paths to load resources, so you need to recompile if you want to proxy dashboard in a subdirectory. These are not directly supported by either the Manager API or the proxy-rewrite plugin in APISIX.

Of course, we can take some measures to improve it, if you are willing to try.

Here are the configures about it.

base: '/',
publicPath: '/',

Got it! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants