Apache third level domain name configuration - apache

i have specific rewrite like
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteRule .* /app_dev.php
and i need domain names like hello.epsilon.localhost and example.epsilon.localhost will go to epsilon.localhost virtualhost (sorry for my bad english)
full virtualhost for epsilon.localhost
<VirtualHost *:80>
DocumentRoot "C:/Projects/epsilon/web"
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteRule .* /app_dev.php
<Directory "C:/Projects/epsilon/web">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
ServerName epsilon.localhost
</VirtualHost>
this rewrite for symfony 2.1

I'm using this http://sourceforge.net/projects/acrylic/ as a local DNS server on windows
and this in the Virtual host configuration
<VirtualHost 127.0.0.1>
ServerName devsite.localhost
ServerAlias *.devsite.localhost
DocumentRoot "C:/httpdocs/devsite"
</VirtualHost>

Related

Combine two virtual hosts in one domain with a subdirectory

I have a website example.com served by Apache, and example2.com redirected to port 3001 (using NodeJS). It works with this config:
<VirtualHost *:80>
ServerName www.example.com
DocumentRoot /home/www/example
<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Allow from all
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName www.example2.com
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/socket.io [NC]
RewriteCond %{QUERY_STRING} transport=websocket [NC]
RewriteRule /(.*) ws://localhost:3001/$1 [P,L]
ProxyPass / http://localhost:3001/
ProxyPassReverse / http://localhost:3001/
</VirtualHost>
Now I would like to have this (because I won't renew the domain example2.com):
example.com => served by Apache => /home/www/example
example.com/website2 => redirected to the NodeJS website using 3001 (the one previously served on example2.com)
Question: I'm about to use the following code, but is it a correct use of Directory?
<VirtualHost *:80>
ServerName www.example.com
DocumentRoot /home/www/example
<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Allow from all
Require all granted
</Directory>
<Directory /website2/>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/socket.io [NC]
RewriteCond %{QUERY_STRING} transport=websocket [NC]
RewriteRule /(.*) ws://localhost:3001/$1 [P,L]
ProxyPass / http://localhost:3001/
ProxyPassReverse / http://localhost:3001/
</Directory>
</VirtualHost>
I think you should use the <Location> directives for section based URL for stable operation.
Each section directives have priorities by order and section based. (section applied order)
<Directory> is based physical file system and low priority if the same section layered by multiple directives, such as <Location>, <Directory>, <File> and so on.
For example,
<VirtualHost *:80>
ServerName www.example.com
DocumentRoot /home/www/example
<Directory /home/www/example>
Options FollowSymLinks
AllowOverride All
#Order deny,allow
#Allow from all
# above access control conf mean same with below conf
Require all granted
</Directory>
# Location is not necessary to mod_rewrite directives.
# rewrite conf can be coontrol the conditions with RewriteCond
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/website2/socket.io [NC]
RewriteCond %{QUERY_STRING} transport=websocket [NC]
RewriteRule ^/website2/(.*) ws://localhost:3001/$1 [P,L]
# ProxyPass is now allowed into Location as following patterns,
# but 'ProxyPass http://localhost:3001/' is available into the Location directive but limited in Location URL pattern.
ProxyPass / http://localhost:3001/
ProxyPassReverse / http://localhost:3001/
</VirtualHost>

Several symfony project on one server with the same port

I have a trouble installing two projects on the same server. Some necessary information:
One VPS server
Two symfony projects (each in separate directory)
Subdomains pointing to projects (first.domain.com / second.domain.com)
All projects must be on the same port (80)
My server looks like this:
Root directory: /var/www/html
- index.php (welcome page)
- projecta (first project)
- projectb (second project)
I would like to achieve:
domain.com -> index.php
first.domain.com (domain.com/first) -> first project
second.domain.com (domain.com/second) -> second project
My apache config:
Alias "/first" "/var/www/html/projecta/web"
<VirtualHost *:80>
ServerName vps.net
ServerAlias http://vps.net/first
DocumentRoot /var/www/html/projecta/web
<Directory /var/www/html/projecta/web>
AllowOverride None
Order Allow,Deny
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ first/app.php [QSA]
</IfModule>
</Directory>
ErrorLog /var/log/apache2/first_error.log
CustomLog /var/log/apache2/first_access.log combined
</VirtualHost>
Alias "/second" "/var/www/html/projectb/web"
<VirtualHost *:80>
ServerName vps.net
ServerAlias http://vps.net/second
DocumentRoot /var/www/html/projectb/web
<Directory /var/www/html/projectb/web>
AllowOverride None
Order Allow,Deny
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ projectb/app.php [QSA]
</IfModule>
</Directory>
ErrorLog /var/log/apache2/second_error.log
CustomLog /var/log/apache2/second_access.log combined
</VirtualHost>
My problem is that first project override path to second project (if I change first project server, then second works).
Now looks like:
domain.com -> first project
domain.com/first -> first project
domain.com/second -> second project in web directory (when I click on the app.php then project run).
Solved
I solved the problem in this way (only in apache config file, I don't need any .htaccess file)
Alias "/first" "/var/www/html/projecta/web"
<VirtualHost *:80>
ServerName first.domain.com
ServerAlias *.first.domain.com
DocumentRoot /var/www/html/projecta/web
<Directory /var/www/html/projecta/web>
AllowOverride None
Order Allow,Deny
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ first/app.php [QSA,L]
</IfModule>
</Directory>
ErrorLog /var/log/apache2/first_error.log
CustomLog /var/log/apache2/first_access.log combined
</VirtualHost>
Alias "/second" "/var/www/html/projectb/web"
<VirtualHost *:80>
ServerName second.domain.com
ServerAlias *.second.domain.com
DocumentRoot /var/www/html/projectb/web
<Directory /var/www/html/projectb/web>
AllowOverride None
Order Allow,Deny
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ second/app.php [QSA]
</IfModule>
</Directory>
ErrorLog /var/log/apache2/second_error.log
CustomLog /var/log/apache2/second_access.log combined
</VirtualHost>
Currently alias didn't work, but for the moment it is enough.

Apache VirtualHost issue not able to run site with htaccess configuration

I am having two domains example xyz.xx and pqrs.net and pointing to same IP.
xyz.xx apache htaccess configuration was done long back and running perfectly fine with this config
Listen : 80
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin testacc#gmail.com
DocumentRoot /www/docs/xyz.xx
ServerName xyz.xx
ServerAlias www.jxyz.xx
<Directory "/www/docs/xyz.xx">
AllowOverride None
Options All
Order allow,deny
Allow from all
DirectoryIndex index.php index.html index.htm
</Directory>
JkMount /test/*.jsp router
JkMount /test/*.html router
</VirtualHost>
Now I am trying to configure htaccess for pqrs.net but facing difficulties , Not sure why it is happening.Need Help.
Here is my other part of htaccess configuration added for pqrs.net:
Listen : 8081
NameVirtualHost XXX.XX.XX.XX:8081
<VirtualHost XXX.XX.XX.XX:8081>
ServerAdmin hello#gmail.com
DocumentRoot /www/docs/pqrs.net
ServerName pqrs.net
ServerAlias www.pqrs.net
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_REFERER} !^$
RewriteRule ^/$ /xxx/usa/index.html [L,PT]
RewriteCond %{REQUEST_URI} !^/xxx/.*
RewriteCond %{REQUEST_URI} !^.*\.do.*
RewriteRule ^/(.*) /xxx/$1 [L,PT]
JkMount /property/*.jsp xxxrouter
JkMount /property/*.html xxxrouter
<Directory "/www/docs/">
AllowOverride None
Options All
Order allow,deny
Allow from all
DirectoryIndex index.html
</Directory>
</VirtualHost>
and here is my workers.properties
worker.list=router
worker.list=xxxrouter
worker.xxxrouter.port=8011
worker.xxxrouter.host=localhost
worker.xxxrouter.type=ajp13
worker.xxxrouter.reply_timeout=100000
worker.router.port=8009
worker.router.host=localhost
worker.router.type=ajp13
worker.router.reply_timeout=100000
Please help me on this , when i am trying to access pqrs.net , it shows me this error message on browser.
The requested URL /xxx/usa/index.html was not found on this server.

Configuring apache2 vhost

I have the following vhost below, my goal with him is:
Redirect all access to https (OK)
Configure my ssl certificate (OK)
Remove www from url
I still can not configure my vhost to remove the www and force the url (using 301) to the url without the www
<VirtualHost *:80>
RewriteEngine on
ReWriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R=301,L]
</VirtualHost>
<VirtualHost *:443>
SSLEngine On
SSLCertificateFile /usr/local/ssl/api_site_com.crt
SSLCertificateKeyFile /usr/local/ssl/myserver.key
SSLCACertificateFile /usr/local/ssl/api.site.com.cer
ServerName api.site.com
ServerAlias www.api.site.com
DocumentRoot "/var/www/api.site.com/public"
<Directory "/var/www/api.site.com/public">
Options Includes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Could anyone help me?
I use these two lines to remove the 'www':
RewriteCond %{HTTP_HOST} !^example\.com [NC]
RewriteRule ^/(.*) http://example.com/$1 [R=301,L]

VirtualHost problem

Can someone tell me why I can't view my index.php from the subdir /oorbellenboutique/?
It shows http:// www.oorbellenboutique.nl/startpagina/index.php, but it must be the index.php from f:/inetpub/wwwroot/oorbellenboutique
The correct URL is: http:// www.oorbellenboutique.nl/index.php
My DNS is:
A *.oorbellenboutique.nl → 83.87.163.224
A oorbellenboutique.nl → 83.87.163.224
CNAME www.oorbellenboutique.nl → oorbellenboutique.nl
My URL is: http://www.oorbellenboutique.nl
I'm running Apache 2.x
NameVirtualHost 192.168.0.199:80
NameVirtualHost 192.168.0.199:443
<VirtualHost 192.168.0.199:80 192.168.0.199:443>
ServerName oorbellenboutique.nl
ServerAlias www.oorbellenboutique.nl
DocumentRoot f:/inetpub/wwwroot/oorbellenboutique
RewriteEngine On
KeepAlive Off
DocumentRoot "f:/inetpub/wwwroot"
<Directory f:/inetpub/wwwroot/oorbellenboutique>
DirectoryIndex index.php
Order deny,allow
Allow from all
</Directory>
RewriteCond %{HTTP_HOST} ^(?:www\.)?oorbellenboutique\.nl$
ReWriteRule ^(.*) /oorbellenboutique/$1
</virtualhost>
This works but the URL is now:
http:// www.oorbellenboutique.nl/oorbellenboutique/index.php
How can I make the URL shorter like:
http:// www.oorbellenboutique.nl/index.php
NameVirtualHost 192.168.0.199:80
NameVirtualHost 192.168.0.199:443
< VirtualHost 192.168.0.199:80 192.168.0.199:443>
ServerName www.oorbellenboutique.nl
ServerAlias *.oorbellenboutique.nl oorbellenboutique.nl
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www.)?oorbellenboutique.nl$
<Directory f:/inetpub/wwwroot/oorbellenboutique>
DirectoryIndex index.html index.php
Order deny,allow
Allow from all
</Directory>
RewriteRule ^/$ /oorbellenboutique/ [R]
< /virtualhost>
Try adding a RewriteBase directive immediately following the RewriteEngine directive:
RewriteBase f:/inetpub/wwwroot
That is not the same as DocumentRoot for functionality -- it is needed for mod_rewrite.