配置阿帕奇。反向代理和别名

时间:2021-07-12 11:43:14

标签: linux apache

在文件 /etc/apache2/sites-available/000-default.conf 中

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    ProxyPass / http://localhost:7000/
</VirtualHost>

当我在浏览器中输入地址 http://example.com 时,我会收到运行在端口 7000 上的应用程序的响应。 需要在设置中添加什么,以便在浏览器中输入 http://example.com 时,我会收到 /var/www/html/ 目录的内容,并且在输入 http://example.com/emby/ 时,来自7000端口上的应用程序?

2 个答案:

答案 0 :(得分:0)

根据https://httpd.apache.org/docs/2.4/mod/mod_proxy.html你需要做的

ProxyPass "/emby" "http://localhost:7000/"
ProxyPassReverse "/emby" "http://localhost:7000/"

请记住,ProxyPass 和 ProxyPassReverse 不会重写任何 HTML 或 JS,因此如果您有例如从/或使用某些绝对路径加载的 SPA,它可能会停止工作。

答案 1 :(得分:0)

在此答案中找到了解决我的问题的方法:httpd - reverse proxy on multiple ports

因此,设置如下所示:

ProxyPass /emby/ http://localhost:7000/
ProxyPassReverse /emby/ http://localhost:7000/

我还创建了一个文件夹:

mkdir /var/www/html/emby
相关问题