2011-02-16 14 views
29

Trafiği arka uç sunucuma iletmeden önce temel proxy'm ile ters proxy yapılandırmaya çalışıyorum. Herhangi biri bana bir çözüm verebilir. BuradaTemel kimlik doğrulamasıyla Apache ters proxy'si

Örnek:

Kullanıcı (internet) -> ters proxy/sankonlar sunucusu (burada temel kimlik doğrulaması eklemek gerekir) -> arka uç sunucusu (non doğrulanmış)

cevap

50

Burada talimatları izleyebilirsiniz: Authentication, Authorization ve Access Control. Geriye doğru proxy için temel fark, dokümanlar sadece Dizin bloklarda izin konum söylemek bile, bir Yer bloğunun içinde yetkilendirme şeyler koymak isteyeceksiniz ki: Yer bloğu dışında

<Location /> 
    AuthType Basic 
    ... 
</Location> 

sen gibi proxy komutları koyabilirsiniz:

ProxyPass/http://localhost:8080/ 
+0

Evet, hatta ters proxy ile çalışır apache güncellemek doğrulaması kullanacak şekilde ters proxy düzenleyin. Kayıt için – lzap

+1

[doc] (http://httpd.apache.org/docs/2.2/mod/directive-dict.html#Context) bu bağlamda çalıştığını gösterir. "dizin Bu bağlamda geçerli olarak işaretlenmiş bir yönerge, Yapılandırma Bölümlerinde belirtilen kısıtlamalara tabi olarak , , ve kapsayıcılarında sunucu yapılandırma dosyalarında kullanılabilir." – Pete

16

Burada bir veritabanına karşı https üzerinden temel kimlik doğrulaması gerçekleştirmek için kullandık yapılandırma var. Arka uç sunucum Tomcat'i çalıştırıyor ve ona AJP kullanarak bağlanıyorum. Komik bağlantı noktası numarası (4443), standart bağlantı noktası (443) zaten kullanılmış ve aynı bağlantı noktasında birkaç https hizmetini yapılandırmak istemedim. senin apache2 Sonra utils paketi

sudo apt-get install apache2-utils 

varsa

<IfModule mod_ssl.c> 
NameVirtualHost *:4443 
<VirtualHost *:4443> 
     ServerAdmin [email protected] 
     ServerName ws.myserver.se 
     ServerAlias ws.myserveralias.se 
     ErrorLog /var/log/apache2/ajpProxy.error.log 

     # Possible values include: debug, info, notice, warn, error, crit, 
     # alert, emerg. 
     LogLevel info 

     CustomLog /var/log/apache2/ajpProxy.log combined 

     DBDriver mysql 
     DBDParams "host=127.0.0.1 port=3306 user=proxyAuthUser pass=yourDbPasswordHere dbname=yourDbName" 
     DBDMin 4 
     DBDKeep 8 
     DBDMax 20 
     DBDExptime 300   

     <Proxy *> 
       # core authentication and mod_auth_basic configuration 
       # for mod_authn_dbd 
       AuthType Basic 
       AuthName "Backend auth name" 
       AuthBasicProvider dbd 

      # core authorization configuration 
       Require valid-user 

       # mod_authn_dbd SQL query to authenticate a user 
       AuthDBDUserPWQuery \ 
       "SELECT password FROM user WHERE emailAddress = %s" 

       AddDefaultCharset Off 
       Order deny,allow 
       Allow from all 
     </Proxy> 

     ProxyPass/ajp://localhost:8009/ 
     ProxyPassReverse/ajp://localhost:8009/ 

     # SSL Engine Switch: 
     # Enable/Disable SSL for this virtual host. 
     SSLEngine on 

     # A self-signed (snakeoil) certificate can be created by installing 
     # the ssl-cert package. See 
     # /usr/share/doc/apache2.2-common/README.Debian.gz for more info. 
     # If both key and certificate are stored in the same file, only the 
     # SSLCertificateFile directive is needed. 
     SSLCertificateFile /etc/apache2/ssl/yourCertificateFile.crt 
     SSLCertificateKeyFile /etc/apache2/ssl/yourPrivateKeyFile.key 
     <FilesMatch "\.(cgi|shtml|phtml|php)$"> 
       SSLOptions +StdEnvVars 
     </FilesMatch> 
     <Directory /usr/lib/cgi-bin> 
       SSLOptions +StdEnvVars 
     </Directory> 

     BrowserMatch "MSIE [2-6]" \ 
       nokeepalive ssl-unclean-shutdown \ 
       downgrade-1.0 force-response-1.0 
     # MSIE 7 and newer should be able to use keepalive 
     BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown 
</VirtualHost> 
</IfModule> 
2

Birincisi, kontrol kullanıcı adı ve şifre koymak.

sudo htpasswd -c /etc/apache2/.htpasswd <username> 

Bundan sonra

<VirtualHost *:80> 
    ProxyPreserveHost On 

    ProxyPass/http://someaddress:1234/ 
    ProxyPassReverse/http://someaddress:1234/ 

    Timeout 5400 
    ProxyTimeout 5400 

    ServerName dev.mydomain.com 
    ServerAlias *.dev.mydomain.com 

    <Proxy *> 
     Order deny,allow 
     Allow from all 
     Authtype Basic 
     Authname "Password Required" 
     AuthUserFile /etc/apache2/.htpasswd 
     Require valid-user 
    </Proxy> 
</virtualhost> 

En azından,

sudo service apache2 reload