274920831 发表于 2017-06-09 17:55

apache做反向代理时如何配置达到只允许几个固定的IP访问网站

这是旧的配置文件,配置文件的路径为/etc/apache2/sites-enabled/wy_server_config.bak,内容如下:
<VirtualHost *:80>
    ServerName wy-c.pala-pala.com
    DocumentRoot /opt/nfcm/mobile
    RewriteEngine On
    RewriteRule "^/$" /template/login.html
    <Directory /opt/nfcm/mobile/>
      DirectoryIndex login.html
      Options -Indexes FollowSymLinks MultiViews
#      Order allow,deny
#      Allow from all
         Order deny,allow
         Deny from all
         Allow from 8.8.8.8
         Allow from 7.7.7.7
         Allow from 6.6.6.6
         Allow from 5.5.5.5
    </Directory>
    Alias /static /opt/nfcm/mobile/static
    ErrorLog ${APACHE_LOG_DIR}/wy-error.log
    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn
    CustomLog ${APACHE_LOG_DIR}/wy-access.log combined
</VirtualHost>

新的配置文件路径为/etc/apache2/sites-enabled/wy_server_config ,文件内容如下所示,做了反向代理
<VirtualHost *:80>
    ServerName wy-c.pala-pala.com

    ProxyPreserveHost On
    ProxyRequests Off
    ProxyPass / http://127.0.0.1:1337/
    ProxyPassReverse / http://127.0.0.1:1337/

    ErrorLog ${APACHE_LOG_DIR}/wy-error.log
    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel debug
    CustomLog ${APACHE_LOG_DIR}/wy-access.log combined
</VirtualHost>

我现在的目的是要在新的配置文件里面来做只允许几个固定IP地址可以访问,拒绝其它的IP地址,我添加了如下内容:
<VirtualHost *:80>
    ServerName wy-c.pala-pala.com
    DocumentRoot /opt/nfcm/mobile   
      <Directory /opt/nfcm/mobile/>
      DirectoryIndex login.html
      Options -Indexes FollowSymLinks MultiViews
         Order deny,allow
         Deny from all
         Allow from 8.8.8.8
         Allow from 7.7.7.7
         Allow from 6.6.6.6
         Allow from 5.5.5.5
    </Directory>

    ProxyPreserveHost On
    ProxyRequests Off
    ProxyPass / http://127.0.0.1:1337/
    ProxyPassReverse / http://127.0.0.1:1337/

    ErrorLog ${APACHE_LOG_DIR}/wy-error.log
    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel debug
    CustomLog ${APACHE_LOG_DIR}/wy-access.log combined
</VirtualHost>

但是重启apache后没有起到任何作用,还是所有IP都可以访问此网站,请问我应该如何来配置才可以达到目的。

页: [1]
查看完整版本: apache做反向代理时如何配置达到只允许几个固定的IP访问网站