![](/img/trans.png)
[英]How to use Apache as a reverse-proxy for WebSockets with Undertow as the server
[英]How to reverse-proxy using apache web server to google cloud run services?
我有一些由 HTTPS 保护的谷歌云运行服务端点。 我想设置我的 apache 网络服务器以反向代理到服务中,以便使用我定义的 URL 的人取回服务响应。 我曾尝试使用 mod_proxy 和 mod_rewrite 代理服务端点,但它给了我 500 内部服务器错误。 怎么做到呢? 最坏的情况请为此分享 nginx 解决方案。 我试过的配置:
<VirtualHost *:80>
ServerName hello.world.com
ServerAlias hello.world.com
RewriteEngine On
RewriteRule ^ https://helloworld-zxtb3wfs2a-de.a.run.app [P]
</VirtualHost>
顺便说一句,端点是一个网站,而不仅仅是一个简单的 JSON 响应。 尽管即使是 JSON 响应也不适合我。
在将查询重写回 Cloud Run 端点 (*.run.app) 时,您需要确保更新Host
header 以匹配 that.run.app 域名。 否则,Cloud Run 的前端 IP 将不知道将其发送到哪里。
检查this question this question on how to do this with mod_rewrite,并确保您使用ProxyPreserveHost Off
。
此外,由于您获得的是 HTTP 500,请确保检查应用程序日志以查看应用程序处理此请求的方式是否有问题。
我假设您已经使用 --ingress internal 选项部署了云运行服务,因此没有反向代理就没有人可以访问 Cloud Run。
按照以下步骤在云运行服务前创建反向代理。 如果您没有安装自签名 SSL 并且您配置了自己的 SSL,则可以跳过步骤 2 - 5
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/apache-selfsigned.key -out /etc/ssl/certs/apache-selfsigned.crt
SSLCertificateFile /etc/ssl/certs/apache-selfsigned.crt
SSLCertificateKeyFile /etc/ssl/private/apache-selfsigned.key
sudo a2enmod ssl
sudo a2enmod headers
sudo a2ensite default-ssl
sudo apache2ctl configtest
sudo systemctl restart apache2
<VirtualHost *:80>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ProxyPreserveHost On
ProxyPass / https://CLOUD-RUN-URL-as.a.run.app/
ProxyPassReverse / https:///CLOUD-RUN-URL-as.a.run.app/
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerAdmin webmaster@localhost
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLProxyEngine On
ProxyPass / https://CLOUD-RUN-URL-as.a.run.app/
ProxyPassReverse / https://CLOUD-RUN-URL-as.a.run.app/
SSLCertificateFile /etc/ssl/certs/apache-selfsigned.crt
SSLCertificateKeyFile /etc/ssl/private/apache-selfsigned.key
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
</VirtualHost>
</IfModule>
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod proxy_balancer
sudo a2enmod ssl
sudo apache2ctl configtest
sudo systemctl restart apache2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.