我有一个简单的 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 方面。
如何正确链接这些文件?是否需要重写?
最佳答案
问题是,默认情况下,使用 hgserve
启动的 Web 服务器不会在其生成的 URL 中添加任何前缀。它无法知道您是对/mercurial 位置的 NGinx 代理传递请求。
您必须设置要与 --prefix
选项一起使用的前缀。 hg helpserve
告诉我们有关该选项的信息:
--prefix PREFIX prefix path to serve from (default: server root)
所以只需这样运行服务器:hgserve --prefix Mercurial
一切都会好起来的! (不要忘记删除您的别名...)
如果您愿意,也可以在配置文件中设置前缀选项:
[web]
prefix = mercurial
关于mercurial - hg 中的损坏链接通过 proxy_pass 在 nginx 后面提供服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8439349/