
我的網站使用 apache httpd 對 Express 中運行的應用程式(Node.js 應用程式)進行反向代理。有 2 台 Express 伺服器,一台用於後端,另一台用於前端託管。現在,我正在嘗試阻止傳入我的網站的惡意請求,以便它會返回 404 或錯誤請求。
我的 some-site-ssl.conf 範例如下,但它看起來並沒有阻止惡意網站,任何幫助都會很棒!謝謝。
<VirtualHost _default_:443>
ServerAdmin webmaster@localhost
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/some-site.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/some-site.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http://(www\.)?.*(-|.)?bad-word(-|.).*$ [NC]
RewriteCond %{HTTP_REFERER} ^https://(www\.)?.*(-|.)?bad-word(-|.).*$ [NC]
RewriteRule ^(.*)$ - [F,L]
ProxyRequests On
ProxyPass /api http://some-site.com:3000/api
ProxyPassReverse /api http://some-site.com:3000/api
ProxyPass / http://some-site.com:4226/
ProxyPassReverse / http://some-site.com:4226/
</VirtualHost>
答案1
您可以使用標籤控制對任何資源的訪問Location
,並且使用它,您可以停用某些主機對您的資源的訪問,如下所示:
<Location "/denied/resource">
<RequireAll>
Require not ip 1.2.3.4
Require not host spammer.domain
Require all granted
<RequireAll>
</Location>
訪問權限是從上到下繼承的,因此拒絕訪問/
實際上會將該客戶端鎖定在您的站點之外(當然,除非授予較低級別的資源訪問權限,因此可能無法訪問/
,但能夠訪問/this/one/
)。看Apache HTTP 伺服器文檔了解更多。
就像@Freddy 所說,你真的應該刪除該ProxyRequests On
行。