1 year ago

#325672

test-img

ehliaskinnesvegahi

Allow only specific ports on Apache non-SSL requests and redirect

I am serving 3 NodeJS websites on Apache. The VirtualHosts of these websites are as follows:

website1

<VirtualHost *:80>
    DocumentRoot "/var/www/html/[website1]"
    ServerName "[website1_domain]"
    ServerAlias "www.[website1_domain]"
    ProxyPass / http://localhost:[website1_port]/
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.[website1_domain] [OR]
RewriteCond %{SERVER_NAME} =[website1_domain]
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

website2

<VirtualHost *:80>
    DocumentRoot "/var/www/html/[website2]"
    ServerName "[website2_domain]"
    ServerAlias "www.[website2_domain]"
    ProxyPass / http://localhost:[website2_port]/
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.[website2_domain] [OR]
RewriteCond %{SERVER_NAME} =[website2_domain]
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

website3

<VirtualHost *:80>
    DocumentRoot "/var/www/html/[website3]"
    ServerName "[website3_domain]"
    ServerAlias "www.[website3_domain]"
    ProxyPass / http://localhost:[website3_port]/
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.[website3_domain] [OR]
RewriteCond %{SERVER_NAME} =[website3_domain]
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

For example, if I go to website1_domain like this http://[website1_domain]:[website2_port] website2 opens even though the domain is website1_domain.

How can I prevent this? If I'm going to website1_domain I want http://localhost:[website1_port]/ to run directly.

apache

httpd.conf

vhosts

0 Answers

Your Answer

Accepted video resources