Host Multiple Domains on One Server/IP

2019-08-19 09:22发布

问题:

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.

回答1:

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.