我想要做什麼(所有這些僅在一個服務器上執行);將所有HTTP/HTTPS請求重定向到特定網站,然後返回
(我正在與example.com合作不做任何廣告)。
將所有傳入HTTP/HTTPS請求(端口80和443)重定向到特定網站,例如filter.example.com。在那裏我創建了自己的機制來過濾惡意請求。之後,請求應該返回到請求的網站。
我的問題是,每個請求都被重定向回過濾器,所以有一個無限循環。
你知道任何解決方案或可能替代(Nginx的)?
這是數據包流所顯示的問題;
「User-Request = https://example.com」 - >「Apache將其重定向到= https://filter.example.com」 - >「獲得過濾= https://example.com」 - >「Apache將其重定向回來。
我真的很希望你能理解我的問題。
謝謝。
編輯:
這是我對filter.example.com服務器名稱設置;
<VirtualHost *:80>
ServerName filter.example.com
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</VirtualHost>
<VirtualHost *:443>
ServerName filter.example.com
RewriteEngine On
DocumentRoot /var/www/filter/
SSLEngine On
SSLCertificateFile /etc/letsencrypt/live/filter.example.com/cert.pem
SSLCertificateChainFile /etc/letsencrypt/live/filter.example.com/chain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/filter.example.com/privkey.pem
ErrorDocument 404 /error404.html
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
</VirtualHost>
這裏爲我的 「真實」 的網站;
<VirtualHost *:80>
ServerName example.com
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</VirtualHost>
<VirtualHost *:443>
ServerName example.com
RewriteEngine On
DocumentRoot /var/www/html/
SSLEngine On
SSLCertificateFile /etc/letsencrypt/live/example.com/cert.pem
SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
ErrorDocument 404 /error404.html
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
</VirtualHost>
大衛寫道:
您真的會在重定向循環中結束,因爲www.example.com的請求1將重定向到filter.example.com,並無休止地再次返回到www.example.com。 爲了避免這種情況,在filter.example.com中添加一個cookie/header到來自www.example.com的傳入請求(當然,在完成過濾器過程之後),例如Filter:true,所以您知道這已經是過濾的請求並且不需要去filter.example.com。
server {
server_name filter.example.com;
//logic to filter
add_header 'passed_filter' 'true';
}
如果您重定向邏輯增加一個檢查覈實,如果頭過濾器:真實存在,如果是的如果不是重定向到filter.example.com, - 跳過重定向,並按照正常的執行過程。
//If the header is not set, then we understand that this request should be redirected to filter.example.com
if($sent_passed_filter ~= 'true') {
//logic to redirect to filter
}
是Nginx,因爲我使用的是Apache。是否也有類似的解決方案,但對於Apache?
我會試試看。謝謝。幾分鐘後,我會給你反饋。但標題是可僞造的,或者不是嗎?問候。 – BERNARDO
我編輯了我的帖子,也許你可以幫忙。感謝您的時間。問候。 – BERNARDO
問題不是由於nginx或apache,它的設置方式。根據您所解釋的內容,我認爲您希望將請求發送到過濾器,並在過濾器上發回請求。如果是這種情況,那麼你需要標記你已經處理過的每一個請求,所以它不會以循環結束。 下面是你需要做的,以使其發揮作用,對於你在filter.example.com中處理的每一個請求,添加一個頭來標識這個請求已經被處理,並且在filter.example.com中添加一個檢查器來查看是否頭是存在的,如果是的話,你不需要再次處理請求 – David