Archive

文章標籤 ‘Apache’

設定Apache上跑Django需要注意的幾個小設定

2011年12月2日 尚無評論

在Apache上的部份幾幾乎乎都用設的就行了

但為了整體安全及效能,還是要把幾個小地方設定做一下

這裡我記錄還記得的部份…….

Apache相關的:

檔案:/etc/apache2/conf.d/security

ServerTokens Full

TraceEnable On

檔案:/etc/apache2/ports.conf

NameVirtualHost *
Listen 80
檔案:/etc/apache2/apache2.conf

Timeout 300
KeepAlive Off
<ifmodule mpm_prefork_module>
    StartServers          5
    MinSpareServers       5
    MaxSpareServers      10
    MaxClients          150
    MaxRequestsPerChild   2000
</ifmodule>
<ifmodule mpm_worker_module>
    StartServers          4
    MinSpareThreads      25
    MaxSpareThreads      75
    ThreadLimit          64
    ThreadsPerChild      50
    MaxClients          250
    MaxRequestsPerChild   0
</ifmodule>

#若有 mpm_event_module
#整個mark掉,因為說是過時的東西@@?!
<files ~ "^\.ht">
    Order allow,deny
    Deny from all
    #Satisfy all   #這個不要?!
</files>

設定mod_wsgi:

檔案:/etc/apache2/mods-available/wsgi_module.load

LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so
WSGIPythonOptimize 2

設定site:

檔案:/etc/apache2/sites-available/site

WSGIDaemonProcess site user=www-data group=www-data processes=4 threads=1 display-name=site
WSGIProcessGroup site

WSGIScriptAlias / /path/to/django.wsgi

ServerSignature Off   #不想在錯誤時出現host的資料
Categories: Python, uBuntu Tags: ,

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:

在現有Apache2再安裝新的module – mod_wsgi.so

2010年2月12日 尚無評論

我在開發機上已經先安裝了Apache2,現在需要讓Python能在Apache上執行,得使用一個module,這裡使用wsgi這個module,但得手動make及install
底下是我的過程:

一、到wsgi官網下載wsgi的source code (我是下載現在的最新3.1版,不知道n年後會是更新到幾版^^)
在我的home目錄,執行 (就直接放在home目錄吧)


$ sudo -c wget http://modwsgi.googlecode.com/files/mod_wsgi-3.1.tar.gz

二、下載後,解壓縮:(我這裡會直接解到mod_wsgi-3.1目錄)

$ tar xvfz mod_wsgi-3.1.tar.gz

※注意唷,我現在是3.1,之後是多少~~不知道~~~

三、進入mod_wsgi-3.1目錄吧,要執行底下的指令來確認環境

$ ./configure

我會寫這篇,就是因為在這裡卡到了~,因為我出現一堆apxs找不到的錯誤訊息
上網再找,總算在Apache apxs這則討論找到解決的方法~

因為我是先安裝了Apache2,並沒有source code,所以wsgi在偵測環境時,沒有可用的原始檔
當然我也有用

sudo apt-cache search apxs

來看apxs會是在哪個pakage裡,但還是列了很多,不確定我該裝哪一個,索性還是照著Apache apxs這則討論直接安裝apache2-threaded-dev吧


$ sudo apt-get install apache2-threaded-dev

(老實說,我還沒找到這個安裝後是安裝到哪個位置,不管,晚一點再找吧~)

然後再回到我home下的mod_wsgi-3.1目錄
再次檢查wsgi需要的環境
這回就全找到了
沒有錯誤啦!!!

好,直接執行下面的指令吧

make

照手冊說就是Building The Source Code
但我執行後還沒看到mod_wsgi.so呀
因為,還需要安裝~~
正是底下的指令


$ sudo make install

記住,要以 root 的身份執行呀~

這時一切都ok了,剩下最後一步,讓Apache載入這個mod_wsgi!!

我的這個Apache2因為是安裝在uBuntu 9.10 desktop裡,在Apache的設定位置較不一樣
如下:

$ cd /etc/apache2/mods-available
$ sudo vim wsgi_module.load

然後編輯就是完全一樣的了

LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so

這個mod_wsgi.so絕對位置,請依照實際情況給予正確的位置哦,可能不同的server,放的位置會不同吧~

$ cd /etc/apache2/mods-enabled
$ sudo ln -s ../mods-available/wsgi_module.load .

好了,再重啟一下Apache吧!!

sudo /etc/init.d/apache2 stop
sudo /etc/init.d/apache2 start

就OK了!!

之後,要再實做設定時,再把這篇補齊嘍~

Categories: Python, uBuntu Tags: , ,