httpd.conf for drupal deployment - drupal

I am trying to create a multi drupal site in one server. I have placed my drupal like
/var/www/html/drupal
/var/www/html/drupal01
/var/www/html/drupal02
I cant use subdomains for this appIication and i would like to access each drupal site like http://www.example.com (/var/www/html/drupal) , http://www.example.com/drupal01 (/var/www/html/drupal01)
I am able to configure my first drupal instance ie http://www.example.com. How can I try access my other drupal instances.
<Directory "/var/www/html/rdsadminhelp/">
RewriteEngine On
RewriteBase /
AllowOverride None
Require all granted
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</Directory>

What you are looking for is VirtualHosts
# Ensure that Apache listens on port 80
Listen 80
<VirtualHost *:80>
DocumentRoot "/www/example1"
ServerName www.example.com
# Other directives here
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/www/example2"
ServerName www.example2.com
# Other directives here
</VirtualHost>
https://httpd.apache.org/docs/2.4/vhosts/examples.html

The default root path of apache server in ubuntu for the domain name 'localhost' is pointed to the /var/www/html folder, that's how you can access the /var/www/html/your_project via http://localhost/your_project.
You can actually create a virtual host with a domain name of your preference (eg: your_domain) for your project folder (eg: /home/user/projects/your_project) so that you could access the project by visting the local url http://your_domain. This would require adding your domain name to /etc/hosts file and placing and enabling the virtual host configuration file which contains the domain name and the project directory path. More details: https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-16-04
I have created a bash script to do this step very easily. You just
need to execute the script enter the domain name & project path and it
will create the virtual host for you.
bash script: https://github.com/sudheeshsbabu/VirtualHost
Steps to create virtualhost using the bash script: https://www.zyxware.com/articles/5742/virtual-host-creation-using-bash-script

Related

Redirect Server Aliases to Server Name Over HTTPS on Apache

I have been looking around for an answer to my problem for a while and have read various other answers without coming across one that works for me.
The problem I am trying to solve involves redirecting access to a WordPress site installed on an Apache server. The WordPress site is one of many installed as part of a WordPress Network installation and the site is setup on the domain https://www.mysite1.co.uk.
It is also necessary to access the site using a number of server aliases, which are to be redirected to the root domain. I have created the additional domains as server aliases in the Apache configuration, and have set redirects to ensure that if one of the aliases is entered then it should be redirected to the root domain.
<VirtualHost *:80>
ServerName www.mysite1.co.uk
ServerAlias mysite1.co.uk www.mysite2.co.uk mysite2.co.uk
...
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)\.?$ [NC]
RewriteRule ^ https://www.mysite1.co.uk%{REQUEST_URI} [R=301,L]
</VirtualHost>
<VirtualHost *:443>
ServerName www.mysite1.co.uk
ServerAlias mysite1.co.uk www.mysite2.co.uk mysite2.co.uk
...
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)\.?$ [NC]
RewriteRule ^ https://www.mysite1.co.uk%{REQUEST_URI} [R=301,L]
SSLEngine On
SSLCertificateFile "certs/mysite1.co.uk.crt"
SSLCertificateKeyFile "certs/mysite1.co.uk.key"
</VirtualHost>
This configuration works whenever the user enters one of the aliases using http, they are redirected to https://www.mysite1.co.uk/. However, if they enter the aliases using https, instead of being redirected to https://www.mysite1.co.uk/, they are not being redirected at all.
Have I missed something in the configuration, or do I need to separate the https configuration and add the aliases into their own virtual host to do the redirect.
The sites are hosted on CentOS 7.9.2009 and running Apache 2.4.6.
If I got it correctly, you're trying to redirect every known domain reaching your apache to just one domain and when the connection comes as HTTP you want to redirect it to HTTPS.
To keep the configuration simple, I would create 3 different virtual hosts:
The first one will listen on http and include every domain you want to redirect (including the main one becuase it's listening on http). This virtualhost will redirect everything to the main domain over https:
<VirtualHost *:80>
ServerName main.site.com
ServerAlias mysite.example.com
ServerAlias another.site.com
Redirect permanent / https://main.site.com/
</VirtualHost>
The second one will listen on https port and includes all the domains but the main one and redirect it to your primary domain (it's like the previous one except it doesn't include the main domain)
<VirtualHost *:443>
ServerName mysite.example.com
ServerAlias another.site.com
Redirect permanent / https://main.site.com/
...
SSLEngine On
...
</VirtualHost>
In the end, the main one will just listen on https and will include only the main domain:
<VirtualHost *:443>
ServerName main.site.com
...
SSLEngine On
...
</VirtualHost>
This way, the only virtualhost requiring configuretiona (document root, locations, etc.) is the last one.

IP canonicalization - When IP adress is typed I want it to direct to the domain name

I have Ubuntu 20.04.1 Apache 2.4.41 webserver(digitalOcean) with SSH root access and domain name form GoDaddy.
Running Wordpress version 5.4.2, everything is working fine but I can't figure out how to do IP canonicalization. I have tried several methods with .htaccess but nothing works for me. When IP address is typed I want it to direct to the domain name.
You can use below rewrite rule in httd.conf file.
<VirtualHost XX.XX.XX.XX>
DocumentRoot "/var/www/html"
ServerName test.com
# Other directives here
RewriteEngine On
RewriteCond %{HTTP_HOST} !^test.com$
RewriteRule ^(.*)$ http://test.com$1 [R=301,L]
</VirtualHost>

VirtualHost apache always returns same website not subdomain

I'm using apache 2.2.15, in a virtual machine over CentOS 6, I have a symfony proyect working here and my boss want to load a wordpress website in the same server on a subdomain.
Subdomain is not working, I've tried a lot of configurations, this is the last one used:
mysite.cl.conf (in /etc/httpd/conf.d folder)
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /var/www/html/symfonyProyect/web
ServerName mysite.cl
ServerAlias mysite.cl
ErrorLog /var/log/httpd/symfonyProyect_error.log
CustomLog /var/log/httpd/symfonyProyect_access.log combined
<Location />
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /app.php [L]
</IfModule>
DirectoryIndex app.php
</Location>
</VirtualHost>
<VirtualHost *:80>
ServerName mysubdomain.mysite.cl
DocumentRoot /var/www/html/mysubdomain
<Directory /var/www/html/mysubdomain>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/httpd/mysubdomain_error.log
CustomLog /var/log/httpd/mysubdomain_access.log combined
</VirtualHost>
my hosts file (in /etc folder)
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
myip mysite.cl mysubdomain.mysite.cl
and my hosts.conf
multi on
when I try mysite.cl it shows the symfony website, but when I try mysubdomain.mysite.cl, it gives me the "This site can't be reached" or "ERR_NAME_NOT_RESOLVED".
The if I delete the first VirtualHost block, it showsme the wordpress website ( even using ServerName mysubdomain.mysite.cl).
Am I missing some configuration or something??
The error you are getting is a DNS one not one from Apache. You need to modify the hosts file on same machine you are trying to browse to mysubdomain.mysite.cl.
Open a command prompt/shell on the machine you are running your browser on and just run ping mysubdomain.mysite.cl if it works your browsing should work too. If you get a message something like ping: unknown host mysubdomain.mysite.cl (Linux) or Ping request could not find host mysubdomain.mysite.cl (Windows). then simply edit the hosts file on that system or get a DNS entry added to your name server.
Simply editing /etc/hosts on the server that Apache runs on doesn't cause all other hosts to be able to resolve a hostname to an IP address.

Subdomain always redirect to WWW (home page)

I want, when open subdomain to return existing Wordpress page ex. www.example.com/custom-wordpress-page.
Server OS is CentOS 6.6, while Web Server (httpd) is Apache 2.2.15.
It have installed and configured Wordpress with .htaccess files configured for it's mod_rewrite.
Root folder is /var/www/html.
.htaccess file is in /var/www/html/.htaccess :
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
This configuration is working very well with one domain (ex. example.com). Today I wanted to add subdomain (ex. subdomain.example.com).
I tried multiple solutions including VirtualHosts with/without NameVirtualHost in httpd.conf file, also adding RewrriteCond&RewriteRule
under mod_rewrite in .htaccess file.
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin email-address-redacted
ServerName www.example.com
ServerAlias example.com
DocumentRoot /var/www/html
</VirtualHost>
<VirtualHost *:80>
ServerAdmin email-address-redacted
ServerName subdomain.example.com
ServerAlias subdomain.example.com
Redirect permanent / http://example.com/custom-wordpress-page
</VirtualHost>
Also in first VirtualHost, I tried *.example.com instead off www.example.com.
In second one, I tried to make Reverse Proxy using ProxyPass and ProxyPassReverse.
Instead of using :*80 I tried using IP address of server and domain name.
Using .htaccess Rewrite rule with/without VirtualHosts gave no results.
subdomain.example.com always opens www.example.com instead of www.example.com/custom-wordpress-page.
Keep in mind - there is a lot of threads like this, but I tried many of them, including many tutorials but they aren't working alongside Wordpress.
Edit : Want to add that there are no wildcards in DNS records. There are NS records, one A record for example.com, one A record for subdomain.example.com and CNAME record for www that is poiting to example.com. There are NO *.
There was problem with hosting provider DNS records, configuration was correct, but I had to call provider to check records in their system and fix what is broken. After they done their job, it works correctly.

Wordpress “Post name” permalinks not working

I have a Wordpress website running on Lamp Server on Ubuntu Server 14.04.
I just tried to use the option for Post Name permalinks, and now my pages no longer load up.
I turned on the mod_rewrite function of the Apache server, restarted it, but it still doesn't work.
Also, here's my .htaccess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Note that the content of /wordpress folder has been put directly inside /html
Let's say the name of my website is mywebsite.com.
How can I make it work?
EDIT: Here is my /etc/apache2/sites-available/000-default.conf file
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
I found a fix. So happy!
In short, the fix for me was to go into the WordPress admin dashboard, go to:
“Settings” > “Permalinks” > “Common settings”, and set the radio button to “Custom Structure”
, and paste into the text box:
/index.php/%year%/%monthnum%/%day%/%postname%/
, and click the Save button
have you enabled the use of .htaccess like described here ?
https://help.ubuntu.com/community/EnablingUseOfApacheHtaccessFiles
For those running apache 2.4 and not finding "default" look in /etc/apache2/apache2.conf and edit
Directory
AllowOverride All
Directory
Directory /var/www/>
AllowOverride All
Directory
edit .ht_access
insert this line in IfModule mod_rewrite.c
RewriteRule ^(.*)$ index.php?_REQUEST=$1 [L]
IT work for me.

Resources