Apache2 Apache端口代理

Apache2 Apache端口代理,apache2,apache-config,Apache2,Apache Config,我有一个非Apache服务器监听端口8001和Apache监听端口80。我希望非Apache服务器通过端口80实际为某个虚拟域提供服务 例如: <VirtualHost *:80> Servername example.com # Forward this on to the server on port 8001 </VirtualHost> 但这不起作用 ProxyPass* 星号仅在块中有效。正斜杠就是你想要的 ProxyPass / http://w

我有一个非Apache服务器监听端口8001和Apache监听端口80。我希望非Apache服务器通过端口80实际为某个虚拟域提供服务

例如:

<VirtualHost *:80>
  Servername example.com

  # Forward this on to the server on port 8001
</VirtualHost>
但这不起作用

ProxyPass*

星号仅在块中有效。正斜杠就是你想要的

ProxyPass / http://www.example.com:8001/
ProxyPassReverse / http://www.example.com:8001/
反向代理确保将端口8001服务器发送的重定向调整为代理的规范名称

apache手册中有一些例子。

我在端口80上有一个由apache托管的站点。我还有一个python web服务器在端口8880上侦听,需要通过访问端口8880。使用txyoji的答案,我只需在虚拟主机定义中添加一个代理权限,即可实现此功能,如下所示:

ProxyPass /something http://mydomainname:8880/something
ProxyPassReverse /something http://mydomainname:8880/something
更新

根据您的设置,更好的方法是为“localhost”上的端口设置代理传递。我觉得你在做什么更清楚一点,而且更便携。除此之外,您甚至不必打开该端口的防火墙!您可以在本地代理传递到任何端口,因此如果不需要,没有理由将其公开给外部世界。将所有内容通过端口80导入,让Apache始终“在最前面运行”。然后,你可以担心它的安全性

ProxyPass /something http://localhost:8880/something
ProxyPassReverse /something http://localhost:8880/something

完整的代码如下所示

<IfModule mod_ssl.c>
<VirtualHost *:443>
ProxyPreserveHost On
ServerAdmin webmaster@localhost
ServerName test.example.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ProxyPass / http://localhost:9301/
ProxyPassReverse / http://localhost:9301/

SSLCertificateFile /etc/letsencrypt/live/test.example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/test.example.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

代理主机
服务器管理员webmaster@localhost
ServerName test.example.com
ErrorLog${APACHE_LOG_DIR}/error.LOG
CustomLog${APACHE\u LOG\u DIR}/access.LOG组合
ProxyPass/http://localhost:9301/
ProxyPassReverse/http://localhost:9301/
SSLCertificateFile/etc/letsencrypt/live/test.example.com/fullchain.pem
SSLCertificateKeyFile/etc/letsencrypt/live/test.example.com/privkey.pem
Include/etc/letsencrypt/options-ssl-apache.conf

这也很有帮助。

您可能会在ServerFault上遇到更好的运气。如果您遇到内部服务器错误:
sudo a2enmod proxy
sudo a2enmod proxy\u http
sudo service apache2 restart
我们不应该在stackoverflow上使用mysite.com,请参阅信息链接,但是在你的回答中提供网站的详细信息更容易获得。
<IfModule mod_ssl.c>
<VirtualHost *:443>
ProxyPreserveHost On
ServerAdmin webmaster@localhost
ServerName test.example.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ProxyPass / http://localhost:9301/
ProxyPassReverse / http://localhost:9301/

SSLCertificateFile /etc/letsencrypt/live/test.example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/test.example.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>