0

I have setup my lightsail instance with a static IP and my React app in the htdocs folder. I am trying to prevent anyone from accessing it via the public url. (Making it so that before you can access it, you need to be SSH'd into the lightsail instance.) Currently, my htaccess file currently only redirects the homepage and not any of the other pages. My htaccess file is as follows.

RewriteEngine On
RewriteBase /

    RewriteCond %{HTTP_HOST} ^1.2.3.4$
    RewriteRule ^/?$ http://127.0.0.1:8080 [R=301,L]

    RewriteCond %{HTTP_HOST} ^1.2.3.4/About$
    RewriteRule ^/?$ http://127.0.0.1:8080/About [R=301,L]

EDIT 1: As suggested below:

I have added the suggested code to my virtual host in 000-default.conf. I have also installed what was needed and made sure everything was activated. I am able to restart Apache without any arrors. However, when I navigate to the public IP Address, it does not redirect to localhost. My code is as follows:

<VirtualHost *:*>
    ProxyPreserveHost On
    ProxyPass / http://127.0.0.1:8080/
    ProxyPassReverse / http://127.0.0.1:8080/
    ServerName localhost
</VirtualHost>

1 Answer 1

0

You're probably looking for enabling reverse proxy in Apache. You can read more about it here:

https://httpd.apache.org/docs/2.4/mod/mod_proxy.html

Instead of using the rewrite module, try using the proxy module and add the following lines:

ProxyPass / http://127.0.0.1:8080/ ProxyPassReverse / http://127.0.0.1:8080/

Hope this helps!

2
  • Could you please take a look at my edit above? I am having some trouble with the Proxy.
    – Chris
    Commented Aug 15, 2019 at 6:52
  • Please try using <VirtualHost *:80> and then ServerName domain.com
    – johnsing
    Commented Aug 15, 2019 at 6:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .