Instruktaż/Tutorial Wiele stron w serwerze Web

Silas Mariusz

rm -rf /
Help us, GOD!
5 Kwiecień 2008
10 167
31
2 243
153
39
Nowy Sącz
forum.qnap.net.pl
QNAP
TS-x77
Ethernet
1 GbE
Creating multiple websites on your NAS.
There are already running several apache servers on your NAS. These have different special purposes. To have your NAS serve multiple domains, there is no need to add additional apache servers, you can serve them all from one Apache server.
All the magic lies inside apache, by using VirtualHosts.
First of, you need to create a folderstructure on the NAS, that the apache can utilize.
We already have Qweb, so let's just extend the use of it, by moving all our websites to subfolders.
Qweb:
index.html
HTML files
Folders for the site

Changes to:
Qweb:
site1
HTML files
Folders for the site

site2
HTML files
Folders for the site.

Site3
....

To minimize the damage if the apache.conf file is reset by a firmware you should create your own config file. As we no longer want to use the root of Qweb to hold webserver pages, we can place the additional configuration there.

Qweb:\customization.conf

And then in the config file of the apache server ( /etc/config/apache/apache.conf), we can add
include /share/Qweb/customization.conf
at the bottom of apache.conf
An example of a config file could look like this:

ServerAdmin webmaster@site1.com
ServerName http://www.site1.com
DocumentRoot "/share/Qweb/site1”
<Directory />
Order Deny,Allow
Deny from all
</Directory>
<Directory "/share/Qweb/site1">
Options FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>

ServerSignature Off
ServerTokens Prod

NameVirtualHost *:80

<VirtualHost *:80>
ServerName http://www.site1.com
ServerAlias site1.com http://www.site1.org site1.org
DocumentRoot "/share/Qweb/site1"
<Directory "/share/Qweb/site1">
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog /share/Qweb/logs/site1_error
CustomLog /share/Qweb/logs/site1_access combined
</VirtualHost>

First of we define where to send mail for users that experience errors, we also set a deny for root, which is lacking in the standard config.
Furthermore we limit the info we want to give away, and then we tell apache, that we want to create virtualhosts based on their name on port 80, which is the standard webport.

Finally we define a virtual server based on it's name.
There is the servername, which is what apache is to react on, and then there are aliases created for other sites, or TopLevelDomains, that you want to direct to the same site.
Finally there is a seperate logfile for each website, if you don't want to look at the logfiles, the errorlog and customlog lines can be omitted. Then the apache will use it's standard log file for every transaction.

To create another site, we simply add a new <VirtualHost> ... </VirtualHost> set, that points to another directory.

This way you can have some domains point to the same site, and others to seperate sites.

If you wish to harden the apache a bit more, you should find the Rewrite module, which can be found on the qnap forums, and then add the following lines to the customization config. The apache replies to some very unusual request methods, and there is no need for that, so we just want to redirect them to nothing.

LoadModule rewrite_module libexec/mod_rewrite.so
RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^TRACE [OR]
RewriteCond %{REQUEST_METHOD} ^PROPFIND [OR]
RewriteCond %{REQUEST_METHOD} ^PROPPATCH [OR]
RewriteCond %{REQUEST_METHOD} ^MKCOL [OR]
RewriteCond %{REQUEST_METHOD} ^COPY [OR]
RewriteCond %{REQUEST_METHOD} ^MOVE [OR]
RewriteCond %{REQUEST_METHOD} ^LOCK [OR]
RewriteCond %{REQUEST_METHOD} ^UNLOCK [OR]
RewriteCond %{REQUEST_METHOD} ^LINK [OR]
RewriteCond %{REQUEST_METHOD} ^UNLINK
RewriteRule .* - [F]

ma ktos ochote tlumaczyc?
 
ten sam problem ..
dodalem na koncu .. ale nie wiem czy dobre miejsce do konca
nie wiem czego nie dziala
w wyniku pokazuje oczywiscie tylko to co jest pod domena e.pl ...
co do mysqla to nie moze to tak byc bo co by bylo jakbym chcial pozniej dodac 2 domene ???
a jeszcze kiedys znalazlem sposob na dopisywnaie index.php w headerze nazwy strony spod jakiej ma byc przekierowanie na jaki adres .. moze ma ktos do tego linka ??? tak bedzie chyba.. prosciej


</IfModule>

Include /etc/config/apache/apache-msv2.conf

<VirtualHost *:80>
ServerName http://www.e.pl
ServerAlias http://www.e.pl
DocumentRoot "/share/Qweb/domeny/e"
</VirtualHost>


<VirtualHost *:80>
ServerName http://www.s.info.pl
ServerAlias http://www.s.info.pl
DocumentRoot "/share/Qweb/domeny/s"
</VirtualHost>


<VirtualHost *:80>
ServerName http://www.sk1.pl
ServerAlias http://www.sk1.pl
DocumentRoot "/share/Qweb/domeny/sk1"
</VirtualHost>