Skip to content

Instantly share code, notes, and snippets.

@idhowardgj94
Last active January 6, 2020 05:22
Show Gist options
  • Save idhowardgj94/90d89da37e6b5a7b0ac7026f8d1808ed to your computer and use it in GitHub Desktop.
Save idhowardgj94/90d89da37e6b5a7b0ac7026f8d1808ed to your computer and use it in GitHub Desktop.
debian 10 apache reverse proxy

打開proxy相關的模組。

    sudo a2enmod proxy
    sudo a2enmod proxy_http
    sudo a2enmod proxy_balancer
    sudo a2enmod lbmethod_byrequests

在你的網站設定檔中(如果你使用apache2,通常在/etc/apache2/sites-available底下),加上以下設定:

<VirtualHost *:80>
 # ... some setting

 # 防止apache使用 proxypass。提升安全性。
 ProxyRequests Off
 # 告訴apache將所有的request導向3000 port
 ProxyPass / http://localhost:3000/
 # 告訴apache將 app server回傳的header修改回 localhost:80 (假設 web server在80 port)
 ProxyPassReverse / http://localhost:3000/
 # 在 request 和 respose header 加上 via資訊,讓app server知道請求從哪來的
 # 也可以使用 ProxyPreserveHost On 來 pass 原始的header 資訊
 # ProxyPreserveHost On
 ProxyVia On
</VirtualHost>

記得把site enable後 重啟 apache2

a2ensite <yourConfig>.conf
systemctl restart apache2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment