Apache - multiple websites - allow top folder access - apache

I have multiple websites setup on my Apache2 server. The directory structure is as follows:
/var/www/
/var/www/site1.com
/var/www/site2.com
It is setup such that "www.site1.com" has root folder /var/www/site1, "www.site2.com" has root folder /var/www/site2, and http://server_ip_address has root folder /var/www
However, if I type http://server_ip_address/site1.com, it opens site1.com. I don't want this to happen. (That is, individual sites should be accessible only by typing the correct address).
What is the way to configure this. (Also it would be helpful if you could give tips on best practices for directory structures for multiple websites)?
thanks
JP

The VirtualHost directive can be used to set individual DocumentRoots for each site name.
Have also a look at this document:
http://httpd.apache.org/docs/2.2/vhosts/name-based.html

Configure multiple websites on Ubuntu
Create apache configuration file:
sudo nano /etc/apache2/sites-available/site1.com
Minimal configuration for the virtual host:
<VirtualHost *:80>
DocumentRoot /var/www/site1.com
ServerName www.site1.com
# Other directives here
</VirtualHost>
Create the root folder:
sudo mkdir /var/www/site1.com
Change the permissions of the folder:
sudo chmod -R 775 /var/www/site1.com/
Create a new record in /etc/hosts
sudo nano /etc/hosts
Add the following line:
127.0.0.1 www.site1.com
Create a correct symlinks in sites-enabled:
sudo a2ensite site1.com
Restart the apache:
sudo /etc/init.d/apache2 restart
You have to do the same with the site2.com, site3.com etc...

Related

Config VirtualHosts on Debian/Apache

On my debian/apache server at http://localhost I'm redirected to my api on port 3000 (this is ok)
Now I would like to open another port (8090), in http://localhost:8090 redirected to /var/www/html/
How to make?
Find the default virtual host conf file by running
ls /etc/apache2/sites-available/
There should be a file called deault.conf, or similar. We want to edit this file
sudo nano /etc/apache2/sites-available/default.conf
Make sure that apache actually is listening to your port 8090 by adding, to the top of that document
Listen 8090
Change the rest of the conf file to match your site, so it may look something like this
Listen 8090
<VirtualHost *:8090>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/
# Other directives here
</VirtualHost>
Save the file with a different name in the same folder. The files must end with ".conf". Add the virtual host to enabled sites by running
sudo a2ensite virtual_host_file_name.conf
replacing "virtual_host_file_name.conf" with the name of the file you select in the previous step.
Then restart the apache server
sudo service apache2 reload
It seems like you're only interested in accessing it from localhost, but if you want to access it remotely you might need to check your firewalls.

Host Multiple Domains on One Server/IP

I have phpList already setup and Codeigniter project that I want to add in one server.
The phpList configuration which is located /etc/httpd/conf.d/phplist.conf has:
<VirtualHost *:80>
ServerName phplist.example.com
ServerAdmin admin#example.com
DocumentRoot /var/www/phplist-3.0.5/public_html
LogLevel warn
ErrorLog /var/log/httpd/phplist_error.log
CustomLog /var/log/httpd/phplist_access.log combined
</VirtualHost>
Here is my possible setting for the CI project, but I don't know how to create one.
<VirtualHost *:80>
ServerName listcsv.com
ServerAdmin admin#listcsv.com
DocumentRoot /var/www/citest/index.php
</VirtualHost>
Below the /etc/httpd/conf/httpd.conf file has a IncludeOptional conf.d/*.conf so I think this would include the configuration file on phplist.
I don't know what settings and where configuration file should I go,
should I edit on /etc/httpd/conf/httpd.conf or just add it together with the phpList configuration at /etc/httpd/conf.d/phplist.conf?
I tried accessing phplist at http://phplist.example.com but the site cannot be reached.
I could access the phpList by going to http://server-ip-address/lists/admin on the browser.
Also, I cannot access the CI project.
I would recommend creating the directory that the virtual hosts will be stored in, as well as the directory that tells Apache that a virtual host is ready to serve the website
sudo mkdir /etc/httpd/sites-available # vhost files
sudo mkdir /etc/httpd/sites-enabled # symbolic links for vhost enabled
Tell Apache where to look for virtual hosts
sudo vim /etc/httpd/conf/httpd.conf
Add this line at the end of the file
IncludeOptional sites-enabled/*.conf
Save and exit.
For each website/domain create its own vhost
sudo vim /etc/httpd/sites-available/example1.com.conf
sudo vim /etc/httpd/sites-available/example2.com.conf
sudo vim /etc/httpd/sites-available/example3.com.conf
Enable the virtualhost
sudo ln -s /etc/httpd/sites-available/example1.com.conf /etc/httpd/sites-enabled/example1.com.conf
sudo ln -s /etc/httpd/sites-available/example2.com.conf /etc/httpd/sites-enabled/example2.com.conf
sudo ln -s /etc/httpd/sites-available/example3.com.conf /etc/httpd/sites-enabled/example3.com.conf
We done, restart your Apache server for the changes to take affect
sudo apachectl restart
Don't forget to point your domains to the web server's public IP address.

Apache Virtual Hosts DocumentRoot path

[1] DocumentRoot /var/www/example.com/public_html
[2] DocumentRoot /var/www/example_com/public_html
Which one option is it more preferable? Dotted or underscored?
And once file /etc/apache2/sites-available/example.com.conf is changed, is it needed to re-run also $ sudo a2ensite example.com.conf ? Or change itself is enough? Thanks!
Each option is ok, it's as you want. For my part, on my dedicated server, I'll use example.com syntax.
When you run $ sudo a2ensite example.com.conf for the first time, a symlink is created from /etc/apache2/sites-available/example.com.conf to /etc/apache2/sites-enabled/example.com.conf.
You can change this file at two location, because it's the same file.
If you want to disable your vhost, you should run $ sudo a2dissite example.com.conf

drupal site in my apache2 localhost is not opening

I installed drupal7 in my system using command sudo apt-get install drupal7, it was installed in /use/share folder, my localhost was configured to /var/www. I was able open drupal site in localhost/drupal7/ but i didnt had any drupal7 folder in /var/www. Now due to permissions issues i moved the drupal7 folder to /var/www now i am getting 404 error when i open localhost/drupal7. how to make this work properly....
open this file
sudo nano /etc/apache2/sites-available/drupal7
"sites-available" it means where your site is avalable for example "htdocs"
and change line DocumentRoot "old address" to this
DocumentRoot /var/www/drupal7
if it's not exist so make file drupal7 and past
<VirtualHost *:80>
ServerAdmin webmaster#drupal7
ServerName drupal7
DocumentRoot /var/www/drupal7
</VirtualHost>
and run
sudo a2ensite drupal7
restart your apache with this command
sudo service apache2 restart

Amazon EC2 How Do I Host a PDF File on my Instance?

I am using this guide:
http://codingthis.com/platforms/linux/how-to-host-simple-content-with-amazon-elastic-cloud-computing-ec2/
I have a folder named public_html in my /home/ec2-user directory with a index.html file.
What I have done so far:
sudo yum -y install httpd php
sudo chkconfig httpd on
chmod 755 /home/ec2-user (I HAVE NO IDEA WHAT THIS DOES)
sudo nano /etc/httpd/conf/httpd.conf
(changed DocumentRoot to DocumentRoot /home/ec2-user/public_html)
Now when I go to my www.mywebsite.com it will hit my index.html file. I tried to put a pdf file in my public_html directory, I tried to go to www.mywebsite.com/pdffile.pdf and it says page not found. How do I host my pdf file on my ec2 instance?
EXTRA:
I have a security group enabled for my instance with rules:
ICMP Allow ALL
TCP Allow ALL
UDP Allow ALL
TCP port 80 (Http)
user848118 answered his/her own question: URLs are case sensitive.
Suppose your machine's IP is myipaddress
Put the PDF file in /var/www and browse
http://myipaddress.com/file.pdf
Works for me.