Apache 2.4 : How to allow a specific url ?

如果你有個網站是不允許外部 ip 連入
只永許特定的 ip 連入
這時候可以利用 SetEnv 環境變數的方式來達到目的
這個方法僅適用於 Apache 2.4 的版本
之前的版本可參考參考資源裡面的設定

以下的範例是說明
開放 https://xxx.your.domain/exceed/xxx 給外部的意思
不受限於 Require all denied
注意 SetEnv 最後面的參數跟 Require not 後面的參數要一致


 <VirtualHost *:443>  
   DocumentRoot "/var/www/html/xxx"  
   ServerName xxx.your.domain  
   CustomLog /var/log/httpd/xxx.your.domain-access.log combined  
   ErrorLog /var/log/httpd/xxx.your.domain-error.log
SSLEngine On SSLCertificateFile /etc/letsencrypt/live/xxx.your.domain/cert.pem SSLCertificateKeyFile /etc/letsencrypt/live/xxx.your.domain/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/xxx.your.domain/fullchain.pem
<Directory "/var/www/html/xxx"> AllowOverride All Require all denied Require ip 1.2.3.4 Require ip 5.6.7.8 # allow specific url SetEnvIf Request_URI "^/exceed/$" exceed_url <RequireAny> <RequireAll> Require not env exceed_url Require all granted </RequireAll> </RequireAny> </Directory> </VirtualHost>


參考資源:
System: Access authorization in Apache 2.4

Comments

Popular posts from this blog

CentOS7 如何新增/移除 Rich Rule for firewalld

mac 安裝 mtr

如何設定 SSL VPN 分割通道 on Fortigate 80C