I bought a 2nd domain and I'm trying to set up a 2nd and separate site on the same ubuntu server.
How do I set up the folders and config files to allow my sites to have separate source files which can't access each other?
My apache2 conf file:
/etc/apache2/apache2.conf:
Mutex file:${APACHE_LOCK_DIR} default
PidFile ${APACHE_PID_FILE}
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
HostnameLookups On
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel notice
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf
Include ports.conf
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /var/www/public>
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
AccessFileName .htaccess
<FilesMatch "^\.ht">
Require all denied
</FilesMatch>
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
IncludeOptional conf-enabled/*.conf
IncludeOptional sites-enabled/*.conf
My ports conf file:
/etc/apache2/ports.conf:
Listen 80
<IfModule ssl_module>
Listen 443
</IfModule>
<IfModule mod_gnutls.c>
Listen 443
</IfModule>
My conf file for site 1 (currently working with SSL):
/etc/apache2/sites-enabled/site1.com.conf:
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerName site1.com
DocumentRoot /var/www/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/site1.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/site1.com/privkey.pem
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
BrowserMatch "MSIE [2-6]" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
</VirtualHost>
</IfModule>
My conf for site 2 (I want to set it up as HTTP for now, I'll set up SSL after confirming that it's working):
/etc/apache2/sites-enabled/site2.com.conf:
<VirtualHost *:80>
ServerName site2.com
ServerAlias www.site2.com
DocumentRoot /var/www/site2
</VirtualHost>
I put the 2nd site's config file in /etc/apache2/sites-available and ran a2ensite site2.com.conf, and then ran systemctl reload apache2.
How do I set it up so that each site only has access to its own directory?
If I remove these lines from apache2.conf:
<Directory /var/www/public>
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
Then loading site1.com shows Error 403 Forbidden, even though site1.com.conf has this line:
DocumentRoot /var/www/public
I thought of putting a Directory tag in site1.com.conf, but there is already one:
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
How do I set it up so that both sites can be accessed on their own domain, while neither site can be accessed from a subdirectory of the other?
EDIT:
My question is really about the relationship between these 3 things:
- apache2.conf's "Directory"
- site 1's "DocumentRoot"
- site 2's "DocumentRoot"
And how I should set up my directory structure.
Currently they are set like this:
- /var/www/public
- /var/www/public
- /var/www/site2
Right now if I go to site 2 it says 403 forbidden, because site 2's DocumentRoot is outside the main config file's Directory folder. And I don't want to set site 2's DocumentRoot to /var/www/public/site2, because then that will be inside site 1's directory.
So is it necessary to use this configuration?:
- /var/www/public
- /var/www/public/site1
- /var/www/public/site2
And what's the difference between that and something like this:
- /var/www
- /var/www/site1
- /var/www/site2
If there are server-only files in /var/www, can site 1 or site 2 ever access them insecurely (client browsing to them)?
My question is about how exactly to set up the directory structure, and I don't understand the difference between apache2.conf's "Directory" and sites-enabled conf's "DocumentRoot".