Virtual Host Subsites apache 2.4 - wordpress

I'm setting up 2 wordpress sites. The scenario is that there are two Wordpress installations, in the folder var/www/domain/us and var/www/domain/eu. The domain.com/us should be the default option when you access the site from domain.com
Users access the site through: domain.com/us or domain.com/eu
Right now the setup for virtual host is: (I don't have a real domain name attached, so its only IP address so far)
<VirtualHost *:80>
ServerName [IP-address]
ServerAlias [IP-address]
DocumentRoot /var/www/domain/us
ErrorLog /var/www/html/domain.com/logs/error.log
CustomLog /var/www/html/domain.com/logs/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName [IP-address]/us
DocumentRoot /var/www/domain/us
ServerAlias [IP-address]
ErrorLog /var/www/html/domain.com/logs/error.log
CustomLog /var/www/html/domain.com/logs/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName [IP-address]/eu
DocumentRoot /var/www/domain/eu
ServerAlias [IP-address]
ErrorLog /var/www/html/domain.com/logs/error.log
CustomLog /var/www/html/domain.com/logs/access.log combined
</VirtualHost>
I can access the IP address with the primary virtual host, but the last two IP/us and IP/eu is giving Page not found.
What am I doing wrong?

ServerName interprets the path as part of the hostname. Server name can contain the request scheme, hostname and port, but not the path. Therefore only the first virtual host is valid.
Since you are on Apache 2.4, you can use conditional directives to solve the problem. In the first virtual host add the following, and then remove the other two:
<VirtualHost *:80>
ServerName [IP-address]
ServerAlias [IP-address]
<If "%{REQUEST_URI} =~ m#^/eu.*$#">
DocumentRoot /var/www/domain/eu
</If>
<Else>
DocumentRoot /var/www/domain/us
</Else>
ErrorLog /var/www/html/domain.com/logs/error.log
CustomLog /var/www/html/domain.com/logs/access.log combined
</VirtualHost>

Related

XAMPP Wordpress Site is not accessible from production server

My Needs are
1. Configure Multiple Domain on XAMPP server on production (Woocommerce Site)
2. Configure and enable ssl
Steps i followed
Edited httpd-vshost as
NameVirtualHost *:80
ServerAdmin mail#firstsite.in
DocumentRoot "C:/xampp/htdocs/firstsite"
Allow from all
ServerName firstsite.in
ServerAlias www.firstsite.in
ServerAdmin mail#secondsite.in
DocumentRoot "C:/xampp/htdocs/secondsite"
ServerName secindsite.in
ServerAlias www.secondsite.in
Allow from all
Edited httpd-ssl
<VirtualHost _default_:443>
ServerAdmin admin#localhost
DocumentRoot "C:/xampp/htdocs/firstsite"
ServerName firstsite.in:443
ServerAlias www.firstsite.in:443
ErrorLog "logs/example-error.log"
CustomLog "logs/example-access.log" common
SSLEngine on
SSLCACertificateFile "C:\xampp\apache\conf\mibstore\ca_bundle.crt"
SSLCertificateFile "C:\xampp\apache\conf\mibstore\server.crt"
SSLCertificateKeyFile "C:\xampp\apache\conf\mibstore\server.key"
</VirtualHost>
<VirtualHost _default_:443>
ServerAdmin admin#localhost
DocumentRoot "C:/xampp/htdocs/secondsite"
ServerName secondsite.in:443
ServerAlias www.secondsite.in:443
ErrorLog "logs/example-error.log"
CustomLog "logs/example-access.log" common
SSLEngine on
SSLCACertificateFile "C:\xampp\apache\conf\ricebazzar\ca_bundle.crt"
SSLCertificateFile "C:\xampp\apache\conf\ricebazzar\server.crt"
SSLCertificateKeyFile "C:\xampp\apache\conf\ricebazzar\server.key"
</VirtualHost>
I have obtained SSL certificate from sslforfree and stored them on relevant path
I also edited etc\hosts file
127.0.0.1 firstsite.in
127.0.0.1 secondsite.in
Issue
I can able to browse them from the server(windows) itself , but can't able to access them from outside. the relevant domain names are purchased and added a A record to point the IP.
Notes
Using Amazon AWS EC2 instance
Added Inbound Rules on 80 & 443, And also added firewall rules on 80 & 443
Would you tried in another PC to visit them since you changed your host file on your PC.
If they can be visited then you need remove the record of your host file.
If not, please try:
Does both the A record of WWW and Non-WWW have been pointed to IP.
If pointed, please tell me what error or message you see on browser when you load the websites.
If there're no error or message which means they are blank page, please try to check is there any htaccess file, do you enable the rewrite mod of xampp.

Possible to run React JS and Wordpress on the same web server?

I am using the Wordpress REST API to provide a back end to my React JS front end. Right now both are running on separate Apache servers on AWS and all works well.
Is it possible to run both on the same server? So that my React front end is making requests to Wordpress on the same server?
Sure, if you want to use Apache to handle distributing your frontend and handling the WP backend, read up on Virtual Hosts: https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-14-04-lts
The gist of it is that you'll have a VH for your frontend
<VirtualHost *:80>
ServerAdmin admin#example.com
ServerName example.com
ServerAlias www.example.com <-- see here
DocumentRoot /var/www/example.com/client
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
and a VH for your backend
<VirtualHost *:80>
ServerAdmin admin#example.com
ServerName example.com
ServerAlias api.example.com <-- and here
DocumentRoot /var/www/example.com/server
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

ProxyPass rule for Wordpress Site with Apache2

I have a wordpress site running on wordpress.myorg.com. For authentication I have to redirect it my internal server running CAS server.
Internal Server does not have DNS name. So, I’m using local DNS with IP address in HOST file to redirect to CAS server. All the things working correctly such a way.
Now I wanted to add ProxyPass rules, so that the User only sees wordpress.myorg.com all the time.
After adding ProxyPass rules, when I hit wordpress.myorg.com/wp-login.php it returns page with 500 internal error rather then showing CAS login screen.
Here is the Virtual Host entry I have done in Apache web server for Wordpress Site
<VirtualHost *:80>
ServerAdmin your_email_address
ServerName wordpress.myorg.com
ServerAlias wordpress.myorg.com
DocumentRoot /var/www/html/wordpress
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/html/wordpress>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
RewriteEngine On
Options +FollowSymLinks
RewriteCond %{HTTPS} !=on
RewriteRule ^/?CAS/(.*) https://wordpress.myorg.com/CAS/$1 [R,NE,L]
</VirtualHost>
<VirtualHost *:443>
ServerAdmin your_email_address
ServerName wordpress.myorg.com
ServerAlias wordpress.myorg.com
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/myorg.com.crt
SSLCertificateKeyFile /etc/apache2/ssl/myorg.com.key
ProxyRequests On
ProxyVia On
ProxyPass /CAS/ ajp://cas.myorg.com:8009/CAS/
ProxyPassReverse /CAS/ ajp://cas.myorg.com:8009/CAS/
</VirtualHost>
Any help on this would be appreciable.
Thanks.
Got the issue. I forgot to enable SSLProxyEngine. Just enabled it and its working like a charm.
Edit for HTTPs portion.
<VirtualHost *:443>
ServerAdmin your_email_address
ServerName wordpress.myorg.com
ServerAlias wordpress.myorg.com
SSLEngine on
## Added these lines ##
SSLProxyEngine On
SSLProxyCheckPeerCN on
SSLProxyCheckPeerExpire on
## -- ##
SSLCertificateFile /etc/apache2/ssl/myorg.com.crt
SSLCertificateKeyFile /etc/apache2/ssl/myorg.com.key
ProxyRequests On
ProxyVia On
ProxyPass /CAS/ ajp://cas.myorg.com:8009/CAS/
ProxyPassReverse /CAS/ ajp://cas.myorg.com:8009/CAS/
</VirtualHost>

Why does localhost work but my alias does not?

I currently have this apache2 site configuration:
<VirtualHost *:80>
ServerAdmin admin#example.com
ServerName engine.com
ServerAlias www.engine.com
DocumentRoot /var/www/engine.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
If I type engine.com I just get a blank page.
My directory setup is like this
/var/www/engine.com/public_html/wp-content...
Localhost works fine and wordpress installation is triggered, but as I say engine.com just brings me a blank page.
Don't you need to add
engine.com 127.0.0.1
to your hosts file?

Wordpress + Wordpress Network on Single Server conflict

I have two installs of wordpress on a single Amazon EC2 server. One of them is just a regular wordpress install, the other being a wordpress network install, with WP Domain Mapping installed.
So let's say I have four domain names: site.example.com, multisite.example.com, multisite1.com and multisite2.com
All of the domain names are pointing to the same IP address. Multisite1.com and multisite2.com are domain mapped to blogs under the multisite.example.com wordpress network
On my server httpd.conf is setup as follows:
<VirtualHost *:80>
ServerAdmin root#localhost
DocumentRoot /persistent/html/site1
ServerName site.example.com
ErrorLog logs/site_error_log
CustomLog logs/site_access_log combined
</VirtualHost>
<VirtualHost *:80>
ServerAdmin root#localhost
DocumentRoot /persistent/html/multisite
ServerName multisite.example.com
ErrorLog logs/multisite_error_log
CustomLog logs/multisite_access_log combined
</VirtualHost>
Right now, all of the domains seem to go to the right place - until I start getting to the wp-admin panel.
site.example.com/wp-admin and multisite.example.com/wp-admin appear to work fine.
multisite1.com/wp-admin and multisite2.com/wp-admin both seem to redirect to site.example.com/wp-admin instead of multisite.example.com/wp-admin.
I can't figure out why. I have tried putting all of the domain names in the virtual host as ServerAlias but it doesn't seem to have helped. I've also put in a wildcard ServerAlias under multisite.example.com as well, but no luck.
Any ideas? It is a bizarre install I know, but for the time being for other reasons, I have to get it to work this way. I will eventually separate the two.
Create a new sites-available entry for each of your sub-domain or virtual host for each sub-domain pointing to the same web root and reload the apache. After that all will work fine.
For e.g.
<VirtualHost *:80>
ServerAdmin root#localhost
DocumentRoot /persistent/html/multisite
ServerName multisite1.com
ErrorLog logs/multisite_error_log
CustomLog logs/multisite_access_log combined
</VirtualHost>
<VirtualHost *:80>
ServerAdmin root#localhost
DocumentRoot /persistent/html/multisite
ServerName multisite2.com
ErrorLog logs/multisite_error_log
CustomLog logs/multisite_access_log combined
</VirtualHost>

Resources