Last active
March 1, 2023 04:58
-
-
Save anggadarkprince/8363ac294ddbb247a9edad1a7feeed37 to your computer and use it in GitHub Desktop.
Apache configuration with sub paths that contain other applications: example.com (app1), example.com/warehouse (app2), example.com/sso (app3), example.com/finance (app4), any path except /warehouse, /sso, /finance, will be handled by app1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<VirtualHost *:80> | |
ServerName example.com | |
ServerAlias www.example.com | |
ServerAdmin admin@example.com | |
DocumentRoot /var/www | |
ErrorLog ${APACHE_LOG_DIR}/error.log | |
CustomLog ${APACHE_LOG_DIR}/access.log combined | |
<Directory /var/www/profile/public> | |
Options -Indexes +FollowSymLinks | |
AllowOverride All | |
Require all granted | |
</Directory> | |
# Alias for /warehouse | |
Alias "/warehouse" "/var/www/warehouse" | |
<Directory /var/www/warehouse> | |
Options -Indexes +FollowSymLinks | |
AllowOverride All | |
Require all denied # change to `granted` if it's not working | |
<FilesMatch "\.(php|inc|html|css|js|jpg|jpeg|png|gif)$"> | |
Require all granted | |
</FilesMatch> | |
<FilesMatch "^uploads/.*$"> | |
Require all granted | |
</FilesMatch> | |
<FilesMatch \.php$> | |
SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost/" | |
</FilesMatch> | |
</Directory> | |
<Directory /var/www/warehouse/uploads> | |
Options -Indexes +FollowSymLinks | |
AllowOverride None | |
Require all granted | |
</Directory> | |
# Alias for /sso | |
Alias "/sso" "/var/www/sso" | |
<Directory /var/www/sso> | |
Options -Indexes +FollowSymLinks | |
AllowOverride None | |
Require all granted | |
<FilesMatch "^\.(htaccess|htpasswd|git|svn|log|md|txt|env|env.example|gitignore|sh)$"> | |
Require all denied | |
</FilesMatch> | |
<IfModule mod_rewrite.c> | |
RewriteEngine On | |
RewriteCond %{REQUEST_FILENAME} !-f | |
RewriteCond %{REQUEST_FILENAME} !-d | |
RewriteRule ^(.*)$ index.php/$1 [L] | |
</IfModule> | |
<IfModule mod_headers.c> | |
Header set X-XSS-Protection "1; mode=block" | |
Header always append X-Frame-Options SAMEORIGIN | |
Header set X-Content-Type-Options nosniff | |
Header set Referrer-Policy "no-referrer-when-downgrade" | |
</IfModule> | |
<FilesMatch \.php$> | |
SetHandler "proxy:unix:/run/php/php8.1-fpm.sock|fcgi://localhost/" | |
</FilesMatch> | |
</Directory> | |
# Alias for /finance | |
Alias "/finance" "/var/www/finance" | |
<Directory /var/www/finance> | |
Options -Indexes +FollowSymLinks | |
AllowOverride All | |
Require all granted | |
</Directory> | |
# Alias for /activity | |
Alias "/activity" "/var/www/activity" | |
<Directory /var/www/activity> | |
Options -Indexes +FollowSymLinks | |
AllowOverride All | |
Require all granted | |
</Directory> | |
# Alias for /vms | |
Alias "/vms" "/var/www/vms" | |
<Directory /var/www/vms> | |
Options -Indexes +FollowSymLinks | |
AllowOverride All | |
Require all granted | |
</Directory> | |
# Alias for /hr | |
Alias "/vms" "/var/www/hr" | |
<Directory /var/www/hr> | |
Options -Indexes +FollowSymLinks | |
AllowOverride All | |
Require all granted | |
</Directory> | |
</VirtualHost> | |
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<VirtualHost *:80> | |
ServerName company.com | |
DocumentRoot /var/www/profile/public | |
<Directory /var/www/profile/public> | |
AllowOverride None | |
Require all granted | |
</Directory> | |
RewriteEngine On | |
# Rewrite /finance to /var/www/finance | |
RewriteCond %{REQUEST_URI} ^/finance [NC] | |
RewriteRule ^/finance(.*)$ /var/www/finance$1 [L] | |
# Rewrite /warehouse to /var/www/warehouse | |
RewriteCond %{REQUEST_URI} ^/warehouse [NC] | |
RewriteRule ^/warehouse(.*)$ /var/www/warehouse$1 [L] | |
# Rewrite any other request to /var/www/profile/public | |
RewriteCond %{REQUEST_URI} !^/(finance|warehouse) [NC] | |
RewriteRule ^(.*)$ /var/www/profile/public/$1 [L] | |
ErrorLog ${APACHE_LOG_DIR}/company-error.log | |
CustomLog ${APACHE_LOG_DIR}/company-access.log combined | |
</VirtualHost> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment