Apache2 Ubuntu 12.10 Only Default Virtual Host is recognized - apache2

I've ran into this problem before with other flavors of Linux and typically it's something dumb but I think I've ruled out all those possibilities. I an using multiple virtual hosts on apache2 Ubuntu 12.10. As per Ubuntu default setup:
[ports.conf]
NameVirtualHost *:80
Listen 80
<IfModule mod_ssl.c>
# If you add NameVirtualHost *:443 here, you will also have to change
# the VirtualHost statement in /etc/apache2/sites-available/default-ssl
# to <VirtualHost *:443>
# Server Name Indication for SSL named virtual hosts is currently not
# supported by MSIE on Windows XP.
Listen 443
</IfModule>
<IfModule mod_gnutls.c>
Listen 443
</IfModule>
Apache2.conf is ubuntu default and loads ports.conf.
I have two virtualhosts
<VirtualHost *:80>
ServerName *.staging.mydomain.com
Options -Indexes FollowSymLinks
UseCanonicalName Off
DocumentRoot /var/www/staging/app/application/current/app
ErrorLog "/var/log/error.log"
CustomLog "/var/log/custom_error.log" common
<ifModule env_module>
SetEnv PHP_ENV staging
</ifModule>
<Directory />
AllowOverride none
</Directory>
<Directory "/var/www/staging/app/application/current/app">
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName *.devtest.mydomain.com
Options -Indexes FollowSymLinks
UseCanonicalName Off
DocumentRoot /var/www/devtest/app/application/current/app
ErrorLog "/var/log/error.log"
CustomLog "/var/log/custom_error.log" common
<ifModule env_module>
SetEnv PHP_ENV develop
</ifModule>
<Directory />
AllowOverride none
</Directory>
<Directory "/var/www/devtest/app/application/current/app">
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</Directory>
</VirtualHost>
A request to somevalue.devtest.mydomain.com resolves to the same document root as somevalue.staging.mydomain.com. If I flip the order the VirtualHosts are declared in then this works in reverse; a request to somevalue.staging.mydomain.com will resolve to the same document root as somevalue.devtest.mydomain.com. No matter what I've tried, I cannot get both hosts to work at the same time. I have this working locally on WAMP and had this same issue but it was simply a misplaced NameVirtualHost *:80 that made it work. Moving the Listen and NameVirtualHost out of ports.conf into apache2.conf and removing the Include for ports.conf does not help. Apache generates no errors. Log level is set to debug.
And because I know you'll ask, yes I have enabled these sites using a2enmod. Yes, I have rebooted apache. I've gone so far as to reboot the server entirely. If I enable the default virtualhost that comes with ubuntu $sudo a2enmod default then it will catch all requests for both somevalue.devtest.mydomain.com and somevalue.staging.mydomain.com.
The virtual hosts are enabled and resolving $sudo apache2ctl -S
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80 is a NameVirtualHost
default server *.staging.mydomain.com (/etc/apache2/sites-enabled/wild.mydomain.com:19)
port 80 namevhost *.staging.mydomain.com (/etc/apache2/sites-enabled/wild.mydomain.com:19)
port 80 namevhost *.devtest.mydomain.com (/etc/apache2/sites-enabled/wild.mydomain.com:51)**strong text**
And finally, the requests resolve on the server curl -Lv http://test.staging.mydomain.com
* About to connect() to test.staging.mydomain.com port 80 (#0)
* Trying 1.1.1.1...
* connected
* Connected to test.staging.mydomain.com (1.1.1.1) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.27.0
> Host: test.staging.mydomain.com
> Accept: */*
>
* additional stuff not fine transfer.c:1037: 0 0
* HTTP 1.1 or later with persistent connection, pipelining supported
< HTTP/1.1 200 OK
< Date: Tue, 05 Mar 2013 02:22:28 GMT
< Server: Apache/2.2.22 (Ubuntu)
< X-Powered-By: PHP/5.4.6-1ubuntu1.1
< Vary: Accept-Encoding
< Content-Length: 18
< Content-Type: text/html
<
* Connection #0 to host test.staging.mydomainy.com left intact
<pre>staging</pre>* Closing connection #0
I've removed the IP and domain but it's definitely resolving properly. Everything on the servers run fine and in fact I didn't even notice the issue until I was on the staging environment and noticed data being updated on the devtest domain instead of staging.
I normally do not ask for any help on here and I've scoured the web and Stack Overflow alike. This does not seem to be a problem with incorrect port names, not declaring ServerName in the VirtualHosts, or not declaring the NameVirtualHost *:80 or Listening on the correct port. I'm completely stumped. Also, this same configuration works on an RPM based version of Linux.

Related

Apache2 : How to remove port from URL?

I have the following apache configuration file for a reverse proxy :
<VirtualHost *:80>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
</VirtualHost>
<VirtualHost *:443>
ProxyPreserveHost On
ProxyPass / http://localhost:5000/
ProxyPassReverse / http://localhost:5000/
ErrorLog /var/log/apache2/NewPC-error.log
CustomLog /var/log/apache2/NewPC-access.log common
SSLEngine on
SSLProtocol all -SSLv2
SSLCertificateFile /etc/ssl/private/localhost.crt
SSLCertificateKeyFile /etc/ssl/private/localhost.key
</VirtualHost>
The reverse proxy works properly bu I always have the port number (5000) in the URL.
Is there any way to remove if please ?
Regards,
The configuration looks good and what you described shouldn't happen unless it's the application running behind the proxyPass that is sending a redirect/location to the client including the port.
You can test it simulating requests to the application running on port 5000 with curl (-v option) or the tool you prefer.

Apache Web server to Tomcat proxy redirection settings result in corrupted response issue

When we access the server directly through port 8080 (without proxy settings) we are not getting the randomly corrupted response and when we configured Apache and Tomcat with proxy settings using mod-proxy-ajp and mod-proxy to run on port 80 instead of 8080 we are getting the randomly corrupted response.
We tried using http instead of ajp but it didn't worked.
We also have Websocket in our application
My server configuration :
Apache Tomcat/7.0.56
Apache Web Server/2.4.10
Java version 1.8.0_161
Following is my setting of apache web server to tomcat redirection :
File: /etc/apache2/sites-available/domainname.conf
NameVirtualHost *:80
<VirtualHost *:80>
ServerName domainname
Redirect / https://domainname/
ProxyRequests Off
ProxyPreserveHost On
</VirtualHost>
<VirtualHost *:443>
ServerName domainname
Redirect / https://domainname/myapp/login.html
SSLEngine on
SSLProtocol -all +TLSv1.2
SSLCertificateFile /etc/apache2/ssl/certificate.crt
SSLCertificateKeyFile /etc/apache2/ssl/certificate.key
SSLCertificateChainFile /etc/apache2/ssl/gd_bundle-g2-g1.crt
ProxyRequests Off
ProxyPreserveHost On
ProxyPass /myapp/ ajp://localhost:8009/myapp/ retry=0 timeout=385
ProxyPassReverse /myapp/ ajp://localhost:8009/myapp/
ProxyPass /myapp/busy-details ajp://localhost:8009/myapp/busy-details/ retry=0 timeout=385
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/myapp/order/$
RewriteCond %{QUERY_STRING} ^OrderID=([0-9999999]*)$
RewriteRule ^(.*)$ https://domainname/myapp/#/orders/edit/%1 [L,R=301,NE]
RewriteCond %{REQUEST_URI} ^/myapp/dentist/$
RewriteCond %{QUERY_STRING} ^DentID=([0-9999999]*)$
RewriteRule ^(.*)$ https://domainname/myapp/#/dentist/edit/%1 [L,R=301,NE]
</VirtualHost>
And tomcat server.xml setting
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000"
URIEncoding="UTF-8" redirectPort="8443" maxPostSize="-1" />
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" URIEncoding="UTF-8" />
please see below response we are getting in browser. Here you can see whenever we load our page some part of HTML response is missing this is also happening with normal ajax get request.
In response 1 you can see Response header of one of the HTML page request.
In response 2 you can see we are getting incomplete response with Red dot in chrome network tab.
Server response 1
Server response 2

Virtual host for angular 2 application in apache 2 not working

I need to create a virtual host or domain for my angular 2 application.
In brief, i had followed the below steps:
1) Created virtual host file for my site (From: https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-14-04-lts)
2) build the project in prod mode: ng build --prod (got dist folder)
These are my settings files from the above tutorial link that i had made in my server:
etc\apache2\sites-available\mydomain.com.conf
ServerName mydomain.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/Angular2/path_to_my_app
<Directory /var/www/html/Angular2/path_to_my_app>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
In my windows host file added an entry to my site to map the ip
C:\Windows\System32\drivers\etc\hosts
10.*.*.* mydomain.com
In my server etc/host added an entry
etc\hosts
127.0.0.1 mydomain.com
In my angular 2 application's src folder (where index.html resides)
<IfModule mod_rewrite.c>
Options Indexes FollowSymLinks
RewriteEngine On
RewriteBase /var/www/html/Angular2/path_to_my_app
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
And in the same folders index.html:
<base href="/var/www/html/Angular2/path_to_my_app">
My package.json has:
"start": "ng serve --host mydomain.com"
The created domain seems to load (hopefully, assuming deep links works), but when i hit mydomain.com, i get the angular2's folder structure view in my browser, not my site loaded
Where is my configuration incorrect.
Do i need to configure any other file in angular 2. If so which?
ServerName mydomain.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/Angular2/path_to_my_app/src
in etc\apache2\sites-available\mydomain.com.conf, append /src to DocumentRoot

Error with apache virtual host configuration for symfony project

I created the project using Symfony framework, and when I am runing build in server in prod or dev env runs ok, But now I move project to debian server, install apache and create virtual host. It shows only directory list and not starts the app. I think that is something wrong with my virual host configuration. I am using Apache/2.4.10 (Debian) Server, PHP 5.6.19-0+deb8u1 (cli).
Here is the code for virtual host:
<VirtualHost *:80>
ServerName mose
ServerAlias 10.5.0.62
DocumentRoot /var/www/mose/web
<Directory /var/www/mose/web/>
AllowOverride None
Require all granted
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
</Directory>
# uncomment the following lines if you install assets as symlinks
# or run into problems when compiling LESS/Sass/CoffeScript assets
# <Directory /var/www/mose>
# Options FollowSymlinks
# </Directory>
# optionally disable the RewriteEngine for the asset directories
# which will allow apache to simply reply with a 404 when files are
# not found instead of passing the request into the full symfony stack
<Directory /var/www/mose/web/bundles>
<IfModule mod_rewrite.c>
RewriteEngine Off
</IfModule>
</Directory>
ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined
</VirtualHost>
The right answer was AllowOverride All from Dawid Sajdak. Tnx for help

zend 2 not loading with apache on my computer

Trying to setup zend with apache on my latop running linux mint 16. I'm not sure what I could have missed in the setup, but when I navigate to localhost I just get a blank page.
Install apaache,php, enabled mod_rewrite:
apt-get install apache2
apt-get install php5
apt-get install libapache2-mod-php5
a2enmod rewrite
Copied my zend app (built with the skeleton) to /var/www/t1 (t1 is the app's folder)
Edited: /etc/apache2/sites-enabled/000-default.conf
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
DocumentRoot /var/www/t1/public
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/t1/public/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
RewriteEngine off
<Location />
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]
</Location>
LogLevel warn
</VirtualHost>
Restarted apache
service apache2 stop
service apache2 start
When I browse to http://localhost I just get a blank page.
edit: After turning on error reporting I found the error was:
Fatal error: Undefined class constant 'MYSQL_ATTR_INIT_COMMAND' in /var/www/t1/config/autoload/global.php on line 19
This was because I forgot to install the mysql module so after doing that it solved the issue.
sudo apt-get install php5-mysql
You probably need to add ini_set('display_errors', 1') and ini_set('error_reporting', E_ALL) at the top of your public/index.php, or do that in your php.ini. You are probably having an exception which is happening before ZF2 can catch it (setup related).
That will in first place allow you to see what the error is, and then it is usually trivial to fix it and move on.

Resources