顯示具有 virtual host 標籤的文章。 顯示所有文章
顯示具有 virtual host 標籤的文章。 顯示所有文章

2013/04/11

Basic Authentication for Apache Virtual Host

最近裝了 phpmemcacheadmin 這套 monitor tool 來用,但它本身沒有使用者驗證的機制,雖然是內部使用,但擁有這麼大的權限應該要控管一下。
在不動到 source 的前提,想到了可以在 Apache web server 端加上 basic authentication:


Apache virtual host 設定檔 vhost.conf

<VirtualHost 10.0.0.1:80>
  ServerName example.com
  DocumentRoot /home/user/www
  DirectoryIndex index.php
  <Directory /home/user/www>
    Deny from all
    # Allow from 10.0.2.1 # 允許從這個 IP 來的不用認證
    AuthUserFile ~/.htpasswd
    AuthName authorization
    AuthType Basic
    Satisfy Any
    require valid-user
  </Directory>
</VirtualHost>
重啓 Apache 就生效了


用 htpasswd 建立帳號/密碼設定檔

$ htpasswd ~/.htpasswd brian
New password:
Re-type new password:
Adding password for user brian

關於 htpasswd 的使用方式請參考 htpasswd - Manage user files for basic authentication

2012/02/26

Nginx 基本設定教學

下載與安裝:http://wiki.nginx.org/Install
若 make 的時候出現下面錯誤
make -f objs/Makefile
make[1]: Entering directory `/home/user/src/server/nginx-1.0.14'
cd /usr/lib \
        && if [ -f Makefile ]; then make distclean; fi \
        && CC="gcc" CFLAGS="-O2 -fomit-frame-pointer -pipe " \
        ./configure --disable-shared
/bin/sh: line 2: ./configure: No such file or directory
make[1]: *** [/usr/lib/Makefile] Error 127
make[1]: Leaving directory `/home/user/src/server/nginx-1.0.14'
make: *** [build] Error 2
解決方式:
在 configure 時 --with-pcre 指向 pcre 的 source tree
$ ./configure --with-pcre=~/pcre-8.30
$ make 


基本指令

# 啟動
/usr/local/nginx/sbin/nginx

# 停止
/usr/local/nginx/sbin/nginx -s stop

# Reload
/usr/local/nginx/sbin/nginx -s reload

# 編輯設定檔
vim /usr/local/nginx/conf/nginx.conf

# 檢查設定檔
/usr/local/nginx/sbin/nginx -t


下面列出幾種常用的模式: