2014年12月14日日曜日

apache digest 認証 ; nginx の basic 認証 と server block


http://www.atmarkit.co.jp/flinux/rensai/linuxtips/698apachebasic.html
ほぼこの通りです。


但し
# ls -l /srv/http/
合計 8
-rw-r--r-- 1 root root   28 12月 10 12:03 index.html
drwxr-xr-x 2 root root 4096 12月 10 13:09 member



# head /etc/httpd/conf/httpd.conf
<Directory "/srv/http/member">
    AuthType Basic
    AuthName "Secret Zone"
    AuthUserFile /etc/httpd/.htpasswd
    Require user secret
</Directory>


htpasswd  -c /etc/httpd/.htpasswd secret









cat httpd-on.bat 
sudo mount /dev/sda4 /HTTP
sudo ln -s /HTTP/htdocs/ /srv/http

sudo systemctl restart httpd.service
sudo systemctl restart sshd
sudo /home/tuyosi/nat.bat

echo '----------------------'
ps ax | grep sshd
ps ax | grep httpd
sudo iptables -L




なお
http://www.sotechsha.co.jp/sp/640/server_02.html
を参考にしてダイナミックDNSしてます。


ただし wifiなので グローバルアドレスを割り当ててもらう必要があり、
さらに Uroadaeroで ポートフォワーディングを設定しなければなりませんでした。

今まではNAPTされて グローバルアドレスはもらってませんでした。
ただし グローバルアドレスをもらうと 元のNAPTには戻りませんので リスクを負う覚悟がいります。
一番の危険はwifiルーターに入られて設定を勝手に変更されたり、
wwwサーバに入られたりです。 


intenet
|
|wireless
|
uroadaero wifiルーター
|
|wireless
|
arch linux(www server)



digest認証です。
http://shohei.yokoyama.ac/%E6%8A%80%E8%A1%93%E3%83%A1%E3%83%A2/%E7%99%BD%E9%BB%92%E3%82%B5%E3%83%BC%E3%83%90%E3%83%BCmod_ssl%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB%E8%A8%98%E9%8C%B2#.E3.81.A4.E3.81.84.E3.81.A7.E3.81.AB.E3.83.80.E3.82.A4.E3.82.B8.E3.82.A7.E3.82.B9.E3.83.88.E8.AA.8D.E8.A8.BC.E3.82.82.E3.81.8B.E3.81.91.E3.82.8B

を参考にしました。
AuthUserFileをAuthDigestFileと書いてあるサイトもありますが、古い情報ですとの事

more /etc/httpd/conf/httpd.conf
<Directory "/srv/http/XXX">
  AuthType Digest
   AuthName "YYY"
   AuthDigestDomain /http_ssl/
   AuthUserFile /etc/httpd/.htdigest
   Require user zzz
</Directory>
中略

LoadModule auth_digest_module modules/mod_auth_digest.so #を外します。

htdigest -c /etc/httpd/.htdigest 'YYY' zzz

ですね。













あと 遠くはなれたところからこれにSSHで入ってメインテナンスをするのに
いらないプロセスがあると遅いので止めます。

 cat X-off.bat 


sudo kill `ps ax| grep xinit  | grep -v grep | cut -d ' ' -f 3`

sudo kill `ps ax| grep dhcpcd | grep -v grep | cut -d ' ' -f 3`

sudo kill `ps ax| grep ibus-daemon | grep -v grep | cut -d ' ' -f 3`

sudo kill `ps ax | grep 'chromium' | grep Sl | grep -v type | cut -d ' ' -f 2`




















nginX です デフォルトではchrootかかってない、危ない。

virtualhost(nginxでは server block と言います)  

basic 認証

apacheは ふるくなってます。
virtualhost として使うなら nginxの方がはるかに使いやすい。




# cat /mnt/home/etc/nginx/nginx.conf



############################

worker_processes  1;
events {
    worker_connections  1024;
}

#h>
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;


#---------------



 server {
        listen       80;
        server_name  localhost;
          root     /mnt-nginx/d1;
          index  index.html index.htm;
          auth_basic "Restricted";
          auth_basic_user_file /etc/nginx/1/.htpasswd;
        }
#  /mnt-nginx/1/.htpasswd ではダメです


#----------------------------------mydns
    server {
        listen       80;
        server_name  a.mydns.jp;
        root   /mnt-nginx/d0;
        index  index.html index.htm;
           }


#--------------------------------ddns
    server {
    listen       80;
    server_name  s.sun.ddns.vc;
    root     /mnt-nginx/d1;
    index  index.html index.htm;
    auth_basic "Restricted";                     
    auth_basic_user_file /etc/nginx/1/.htpasswd;   
         }


    server {
    listen       80;
    server_name  k.sun.ddns.vc;
    root     /mnt-nginx/d2;
    index  index.html index.htm;
    auth_basic "Restricted";
    auth_basic_user_file /etc/nginx/2/.htpasswd;
          }


 server {
    listen       80;
    server_name  m.planex.ddns.vc;
      root     /mnt-nginx/d11;
      index  index.html index.htm;
        auth_basic "Restricted";
        auth_basic_user_file /etc/nginx/11/.htpasswd;
        }


#nita.luna.ddns.vc
 server {
    listen       80;
    server_name  n.luna.ddns.vc;
      root     /mnt-nginx/d12;
      index  index.html index.htm;
        auth_basic "Restricted";
        auth_basic_user_file /etc/nginx/12/.htpasswd;
        }

#h<
}









0 件のコメント:

コメントを投稿