首頁 > uBuntu > uBuntu安裝Apache2

uBuntu安裝Apache2

2010年4月1日 發表評論 閱讀評論

安裝指令:

sudo apt-get install apache2

在/etc/apache2/conf.d/charset 檔案中設定語系 (現今的網站應該都用UTF-8了吧)

AddDefaultCharset UTF-8

Apache2 對port設定檔:/etc/apache2/ports.conf

# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default
# This is also true if you have upgraded from before 2.2.9-3 (i.e. from
# Debian etch). See /usr/share/doc/apache2.2-common/NEWS.Debian.gz and
# README.Debian.gz

Listen 80
Listen 8000
Listen 8080
NameVirtualHost *:80
NameVirtualHost *:8000
NameVirtualHost *:8080

<IfModule mod_ssl.c>
    # SSL name based virtual hosts are not yet supported, therefore no
    # NameVirtualHost statement here
    Listen 443
</IfModule>

網站設定檔在:/etc/apache2/sites-available/default
設定啟用檔是:/etc/apache2/sites-enabled/000-default
兩者關係為:/etc/apache2/sites-enabled/000-default –> /etc/apache2/sites-available/default
也可以直接將設定檔置於/etc/apache2/sites-enabled/ 下

原內容:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog /var/log/apache2/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog /var/log/apache2/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>
</VirtualHost>

實作所需內容:原本將所有實做內容放置於default,但實在太長,就做了分割

/etc/apache2/sites-available/web0nono (將各port沒有使用名稱的定為禁止讀取)
/etc/apache2/sites-enabled/001-web0nono -> ../sites-available/web0nono

<VirtualHost *:8080>
    ServerAdmin andy@rdandy.com

    DocumentRoot /var/wwwsites/web0
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /var/wwwsites/web0/>
        Options -Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        deny from all
    </Directory>
</VirtualHost>

<VirtualHost *:8000>
    ServerAdmin andy@rdandy.com

    DocumentRoot /var/wwwsites/web0
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /var/wwwsites/web0/>
       Options -Indexes FollowSymLinks MultiViews
       AllowOverride None
       Order allow,deny
       deny from all
   </Directory>
</VirtualHost>

/etc/apache2/sites-available/web1.rdub.com
/etc/apache2/sites-enabled/003-web1.rdub.com -> ../sites-available/web1.rdub.com

<VirtualHost *:8080>
    ServerAdmin andy@rdandy.com
    ServerName web1.rdub.com
    #ServerAlias web1.rdub.com

    DocumentRoot /var/wwwsites/web1
    #<Directory />
    # Options FollowSymLinks
    # AllowOverride None
    #</Directory>
    <Directory /var/wwwsites/web1/>
        Options -Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>

    #ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    #<Directory "/usr/lib/cgi-bin">
    # AllowOverride None
    # Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    # Order allow,deny
    # Allow from all
    #</Directory>

    ErrorLog /var/log/apache2/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog /var/log/apache2/access.log combined

    #Alias /doc/ "/usr/share/doc/"
    #<Directory "/usr/share/doc/">
    #    Options Indexes MultiViews FollowSymLinks
    #    AllowOverride None
    #    Order deny,allow
    #    Deny from all
    #    Allow from 127.0.0.0/255.0.0.0 ::1/128
    #</Directory>

</VirtualHost>

/etc/apache2/sites-available/db.rdub.com
/etc/apache2/sites-enabled/005-db.rdub.com -> ../sites-available/db.rdub.com

<VirtualHost *:80>
    ServerAdmin andy@rdandy.com
    ServerName  db.rdub.com
    ServerAlias db.rdub.com

    DocumentRoot /var/wwwsites/phpmyadmin
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /var/wwwsites/phpmyadmin/>
        Options -Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>

    #ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    #<Directory "/usr/lib/cgi-bin">
    #   AllowOverride None
    #   Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    #   Order allow,deny
    #   Allow from all
    #</Directory>

    ErrorLog /var/log/apache2/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog /var/log/apache2/access.log combined

    #Alias /doc/ "/usr/share/doc/"
    #<Directory "/usr/share/doc/">
    #    Options Indexes MultiViews FollowSymLinks
    #    AllowOverride None
    #    Order deny,allow
    #    Deny from all
    #    Allow from 127.0.0.0/255.0.0.0 ::1/128
    #</Directory>

</VirtualHost>

※ 設定首頁順序:在/etc/apache2/mods-available/dir.conf

<ifmodule mod_dir.c>
     DirectoryIndex index.php index.html index.htm index.pl index.cgi index.xhtml
</ifmodule>

相關指令:

  • STOP Apache
    sudo /etc/init.d/apache2 stop
  • START Apache
    sudo /etc/init.d/apache2 start
  • RESTART Apache
    sudo /etc/init.d/apache2 restart
  • RELOAD Apache
    sudo /etc/init.d/apache2 reload

如有錯誤還請先進多多指教!!

Categories: uBuntu Tags:
  1. 目前尚無任何的評論。