简体   繁体   中英

ProxyPass custom port Redirect to https

I would like to grand access to certain IP's to mysite.com:1234 but deny that port to other users and redirect them to port 80 or 443, the first part is working with my vhosts file but I can't seem to get the redirection part working, other IP's get 403 error

<VirtualHost 12.123.123.123:443>


<Directory "/home/mysite/public_html">
            
    Options -Indexes -FollowSymLinks +SymLinksIfOwnerMatch
    AllowOverride All 
    SSLRequireSSL
</Directory>

<IfModule mod_proxy.c>
    ProxyRequests Off
    ProxyPreserveHost On
    ProxyVia Full
    ProxyPass / http://127.0.0.1:1234/
    ProxyPassReverse / http://127.0.0.1:1234/

    <Proxy "http://127.0.0.1:1234/">
    
            Deny from all
            allow from 1.1.1.1
            allow from 1.1.1.2
            allow from 1.1.1.3
            allow from 1.1.1.4
    </Proxy>
</IfModule>

One solution would be to implement your proxy rule with mod_rewrite. Rewrite rules have a [P] flag which means "reverse proxy". You could have a rewrite condition that checks for the correct IP addresses before a rule that does the proxy. Then all other requests would fall through to a second rule that does the redirect.

RewriteEngine On

# Reverse proxy for allowed remote addresses
RewriteCond %{REMOTE_ADDR} ^1.1.1.[1234]$
RewriteRule  ^/?(.*)$ http://127.0.0.1:1234/$1  [P,L]

# Redirect everything else to the main site
RewriteRule  ^/?(.*)$ https://mysite.example/$1  [R=301,L]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM