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

我怎么设置他成为一个子目录呢?nginx #4928

Closed
bbhxwl opened this issue Jul 5, 2024 · 12 comments
Closed

我怎么设置他成为一个子目录呢?nginx #4928

bbhxwl opened this issue Jul 5, 2024 · 12 comments
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@bbhxwl
Copy link

bbhxwl commented Jul 5, 2024

我想访问我主站 的/gpt 路径,代理这个地址。
测试了下404,资料加载不了。
location /gpt {
proxy_pass http://127.0.0.1:6003/;
proxy_buffering off;
proxy_read_timeout 100s;
}

@nextchat-manager
Copy link

Please follow the issue template to update title and description of your issue.

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Title: How do I set it to be a subdirectory? nginx

@Interfish
Copy link

Same quesiton here

@lloydzhou
Copy link
Contributor

@bbhxwl @Interfish
try this:

server {
    listen       80;
    server_name _;
    location ~ /(_next|config|google-fonts|serviceWorkerRegister) {
        proxy_pass http://nextchat:3000;
    }
    location /chat {
        rewrite /chat/(.*) /$1 break;
        proxy_pass http://nextchat:3000;
        proxy_buffering off;
        proxy_read_timeout 100s;
    }
}

@lloydzhou
Copy link
Contributor

another version:

server {
    listen       80;
    server_name _;
    location / {
        # can serve other site files, and try "@chat" at last
        try_files $uri $uri/ @chat;
    }
    location @chat {
        rewrite /chat/(.*) /$1 break;
        proxy_pass http://nextchat:3000;
        proxy_buffering off;
        proxy_read_timeout 100s;
    }
}

@lloydzhou lloydzhou added documentation Improvements or additions to documentation enhancement New feature or request labels Jul 10, 2024
@bbhxwl
Copy link
Author

bbhxwl commented Jul 10, 2024

another version:

server {
    listen       80;
    server_name _;
    location / {
        # can serve other site files, and try "@chat" at last
        try_files $uri $uri/ @chat;
    }
    location @chat {
        rewrite /chat/(.*) /$1 break;
        proxy_pass http://nextchat:3000;
        proxy_buffering off;
        proxy_read_timeout 100s;
    }
}

This definitely won't work because my main path has other websites and I just want them to be a part of my website

@bbhxwl
Copy link
Author

bbhxwl commented Jul 10, 2024

@bbhxwl @Interfish try this:

server {
    listen       80;
    server_name _;
    location ~ /(_next|config|google-fonts|serviceWorkerRegister) {
        proxy_pass http://nextchat:3000;
    }
    location /chat {
        rewrite /chat/(.*) /$1 break;
        proxy_pass http://nextchat:3000;
        proxy_buffering off;
        proxy_read_timeout 100s;
    }
}

[emerg] 2408809#2408809: "proxy_pass" cannot have URI part in location given by regular expression, or inside named location, or inside "if" statement, or inside "limit_except" block in

@lloydzhou
Copy link
Contributor

@bbhxwl
Copy link
Author

bbhxwl commented Jul 10, 2024

https://gist.github.com/lloydzhou/1bd2f63a85e5a622716d001a3a9c5a8d

the 2 version, work fine

image

What I mean is that your root directory cannot be used for reverse proxy of other websites, right?

@kilgrims
Copy link

Have you solved it already?

@P2K0
Copy link

P2K0 commented Sep 19, 2024

https://gist.github.com/lloydzhou/1bd2f63a85e5a622716d001a3a9c5a8d

  1. 版本,运行良好

图像

没有用 其他资源跟路径跳转任然 404
这种做法 如果当前站点有其他子站的话 会占用路径
也许需要 next中配置 basePath assetPrefix

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


https://gist.github.com/lloydzhou/1bd2f63a85e5a622716d001a3a9c5a8d

  1. Version, working well

[Image] (https://private- user-images.githubusercontent.com/1826685/347278495-F7644296-704-B758-738D153B6DE1.jwt=eyjhbgcio IJiuzi1niisinr5CCI6IKPXVCJ9.EYJPC3MIOIJNAXRODWIUY29TIIWIYXVKIJOI CMF3LMDPDGH1YNVZXJB250LMNVBSIMTLETUILCJLEHAIOJE3 MJY3MDK5MZysim5izii6MTCYNJCWOTYZNIWICGF0ACI6II8XODI2NJG1lzm0nz 1GTQW16LUFSZ2YAXROBT1BV1M0LUHNQUMTU0HBMJLGTQW16Lunyzwrlbnr Pyww9qutjqvztfnbkelmkyMDKXDKXLWVHC3QTMSSSSSS Uyrnmzjtjgyxdznf9yzxf1zxn0jlgtqw16lurhdgu9mjaynda5mtlumdezmzu 2 wizyluftei1fehbpcmwmczyluftei1cmgy3nmjhndrlz Wi0nde3odflmzmwq5njzimwiwnmi4n2NZEWZDK3NWJLNWYXYTDIGe4ndyyyyynwfkzczyluzwrizWhvc3QMYWQ9mczr ZXLFAWQ9MCZYZXBVX2LKPTAIFQ.YGC2BIBLKGMEBAPWUKHMHQYao4nt5-3WKV_DDZ3VC4))))

It’s useless. Other resources and path jumps are still 404.
This approach will occupy the path if the current site has other sub-sites.
Maybe you need to configure basePath assetPrefix in next

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants