hg 中的损坏链接通过 proxy_pass 在 nginx 后面提供服务
我有一个简单的 Ubuntu 10.10、Nginx、Mercurial、PHP 和 MySQL 堆栈。
当前文件结构:
/opt/nginx/html - document root for nginx (where my website files are)
/opt/nginx/html/.hg - repository data
/usr/share/mercurial/ - where the templates/static folder is
我正在运行托管在 localhost:8000 的 hg -serve。 在此之后,我不太清楚 Mercurial 与其资源之间的关系。
我有以下 Nginx 配置作为我想要的入口点:
location /mercurial/ {
auth_basic "Authentication";
auth_basic_user_file /opt/nginx/html/.hg/file.password;
proxy_pass http://localhost:8000/;
}
除了在身份验证后完全加载 Mercurial 实例之外,这工作正常。我得到了我希望看到的页面,但 /static 引用都已损坏,并且我单击的链接(例如其中一个变更集)也已损坏(找不到它们或将我带回损坏的主页)。它尝试在 my-ip-address/static/... 查找这些文件,这是不正确的。
Mercurial ui 目录位于我的文档根目录 /opt/nginx/html 之外。 /static实际所在的路径是:/usr/share/mercurial/templates 这是问题吗??这些文件位于我的 nginx 文档根目录之外? 当 Mercurial 运行时 /rev 在哪里以及如何确保 Mercurial 使用正确的资源 URL 正确运行?
注意:只需访问 my-ip-address:8000 即可 100% 工作。没有任何损坏,也没有丢失 css 或 js。问题发生在 proxy_pass 上。
我怎样才能正确链接这些文件?是否需要重写?
I have a simple Ubuntu 10.10, Nginx, Mercurial, PHP, and MySQL stack.
Current file structure:
/opt/nginx/html - document root for nginx (where my website files are)
/opt/nginx/html/.hg - repository data
/usr/share/mercurial/ - where the templates/static folder is
I am running hg -serve which is hosted at localhost:8000.
I do not have a clear understanding of how mercurial is linked to its resources after this point.
I have the following Nginx configuration for my desired entry point:
location /mercurial/ {
auth_basic "Authentication";
auth_basic_user_file /opt/nginx/html/.hg/file.password;
proxy_pass http://localhost:8000/;
}
This works fine except for fully loading the Mercurial Instance after authenticating. I get the page i expect to see but the /static references are all broken, and the links I click on such as one of the changesets is broken as well (they are not found or take me back to the broken main page). It tries to find these files at my-ip-address/static/... which is incorrect.
The mercurial ui directory is outside of my document root /opt/nginx/html.
The path of where /static actually is: /usr/share/mercurial/templates
Is this the problem?? That the files are outside of my nginx document root?
When mercurial runs where is /rev and how can i make sure that mercurial runs correctly with the correct resource URLs?
Note: Just going to my-ip-address:8000 works 100%. Nothing is broken and no css or js is missing. The problem is happening with regards to the proxy_pass.
How can I have these files properly linked up? Is a rewrite required?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是,默认情况下,使用
hgserve
启动的 Web 服务器不会向其生成的 URL 添加任何前缀。它无法知道您是对 /mercurial 位置的 NGinx 代理传递请求。您必须设置要与
--prefix
选项一起使用的前缀。hg helpserve
告诉我们有关该选项的信息:所以只需以这种方式运行服务器:
hgserve --prefix Mercurial
一切都应该没问题! (不要忘记删除您的别名...)如果您愿意,也可以在配置文件中设置前缀选项(如果您有):
The problem is that by default, the web server launched with
hg serve
doesn't add any prefix to the URLs it generates. It has no way to know that you're NGinx proxy pass request for the /mercurial location.You must set the prefix to use with the
--prefix
option.hg help serve
tells us this about the option :So just run the server this way :
hg serve --prefix mercurial
and everything should be fine ! (don't forget to remove your alias...)If you prefer, the prefix option can also be set in the configuration file if you have one :
Soultion:我需要将以下内容添加到我的 NGINX 配置文件中;
Soultion: I needed to add the following to my NGINX config file;