2014年12月26日金曜日

nginx で  vitualhost かつ BASIC認証

結構 openbsdのnginxはデリケートだ。
丁寧に扱わないといけない。


archlinxのデフォルトのnginxは chrootされてなくあぶない。
かといって それをきちんとchrootするのはとても大変である。
あやうい wwwサーバーではなんともならない。

また apacheは 古くなったとのこと。
だから nginxに移行した。


/etc/nginx/nginx.conf は結局以下。



--------------------

worker_processes  1;
worker_rlimit_nofile 1024;

events {
    worker_connections  800;
}

#h>
http {

    include       mime.types;
    default_type  application/octet-stream;
    index         index.html index.htm;
    keepalive_timeout  65;
    server_tokens off;


server {
        listen       80;
        listen       [::]:80;
        server_name  localhost;    #<-for test
        root         /var/www/d1;
auth_basic "Restricted";
auth_basic_user_file /var/www/1/.htpasswd; #所有者はwwwにすること。
                      
          }


#0 ほら、basic 認証してるでしょう
    server {
        listen       80;
        listen       [::]:80;
        server_name  a.mydns.jp;
        root         /var/www/d0;
auth_basic "Restricted";
auth_basic_user_file /var/www/1/.htpasswd;
          }

#1
server {
        listen       80;
        listen       [::]:80;
        server_name  s.sun.ddns.vc;
        root         /var/www/d1;
auth_basic "Restricted";
auth_basic_user_file /var/www/1/.htpasswd;
          }

#2
server {
        listen       80;
        listen       [::]:80;
        server_name  k.sun.ddns.vc;
        root         /var/www/d2;
auth_basic "Restricted";
auth_basic_user_file /var/www/2/.htpasswd;
          }

#11
server {
        listen       80;
        listen       [::]:80;
        server_name  member.planex.ddns.vc;
        root         /var/www/d11;
auth_basic "Restricted";
auth_basic_user_file /var/www/11/.htpasswd;
          }

#12
server {
        listen       80;
        listen       [::]:80;
        server_name  n.luna.ddns.vc;
        root         /var/www/d12;
auth_basic "Restricted";
auth_basic_user_file /var/www/12/.htpasswd;
          }
#h>
    } 
 
 
 
自分は openbsdを USBでうごかしている。
それで 4Gしかとれない。
だから データは HDDにいれる必要がある。
しかも LINUXからもアクセスできるように ext2にしている。
 

記憶では
mv  /var/www  /var/www1
mkdir  /var/www
mount_ext2fs /dev/sd0a /var/www
cp -ar /var/www1/*   /var/www 
したと思う。
とにかく USBの /var/wwwを HDDに移した。



 # cat /etc/rc.local 
umount /var/www 

mount_ext2fs /dev/sd0a /var/www # <-----ext2fs

 if [ -x /usr/local/sbin/nginx ]; then echo ' ----- Starting nginx ----- '; /etc/rc.d/nginx -f start fi 



 because 
cat /etc/rc.d/nginx 
#!/bin/sh 
# # $OpenBSD: nginx,v 1.1 2012/02/19 11:34:36 robert Exp $ daemon="/usr/local/sbin/nginx" #<------   いろいろつついているうちに 
                                                                /usr/sbin/nginxが変化した。







 # 2>&1 nginx -V | tr -- - '\n' | grep _module
http_gzip_static_module
http_ssl_module
http_stub_status_module
mail_pop3_module
mail_imap_module
mail_smtp_module



archでは
 2>&1 nginx -V | tr -- - '\n' | grep _module is next
--------------------
imap_ssl_module
http_dav_module
http_gunzip_module
http_gzip_static_module
http_realip_module
http_spdy_module
http_ssl_module
http_stub_status_module
http_addition_module
http_degradation_module
http_flv_module
http_mp4_module
http_secure_link_module
http_sub_module

になってる。




後は
http://www.bsdnow.tv/tutorials/nginx
とか
http://apis.jpn.ph/fswiki/wiki.cgi?page=OpenBSD%2Fhttpd#p13

はありますが、
HTTPSは、メッセージを平文のままで送受信する標準のHTTPと異なり
WebブラウザとWebサーバの間の通信を暗号化して、盗聴改竄を防いでいる。

実現は難しい。

2014年12月13日土曜日

apache2 basic 認証 ; openbsd の grub

OpenBSD httpd does not support authentication.
ということで 
apache-httpd-2.2.27p4.tgzをいれます。

openbsdは usb HDD で動いてるので、 usbを圧迫しないように
公開ファイルを hard disk sd0 におきます。
ln -s ではうまくいかないので、

/etc/rc.local  を
umount /var/apache2/
mount_ext2fs /dev/sd0a  /var/apache2/

if [  -x /usr/local/sbin/apachectl2 ]; then
        echo ' ----- Re  Starting apache -----  ';  /usr/local/sbin/apachectl2 restart
fi

とします。見てのとおり ext2です。
というのは linux からも openbsdからも利用するためです。



やっと  'Basic Auth' ができました。 

www root は /var/apache2/htdocs/ .


conf file iは /etc/apache2/httpd2.conf .


cd /etc/apache2/
htpasswd .htpasswd  XXX
chmod 644  .htpasswd <- correct ?
として ID XXXに対するパスワードをつくります。


# head /etc/apache2/httpd2.conf
<Directory "/var/apache2/htdocs/YYY">
    AuthType Basic
    AuthName "Secret Zone"
    AuthUserFile /etc/apache2/.htpasswd
    Require user XXX
</Directory> 

 
なので 非公開フォルダは /var/apache2/htdocs/YYY で
 
     公開フォルダは /var/apache2/htdocs/ です。
 
 
  
こういった 公開フォルダの中に basic認証フォルダを
つくるという器用なことは
nginx
hiawatha
ではちょっと難しい。 
??   http://qiita.com/minodisk/items/90c6d6cd8f16c34ac10b  ??







 
 
 
  










































4.6 - Soft Updates ext4みたいなジャーナルらしい

Soft Updates is based on an idea proposed by Greg Ganger and Yale Patt 
and developed for FreeBSD by Kirk McKusick. 
SoftUpdates imposes a partial ordering on the buffer cache operations 
which permits the requirement 
for synchronous writing of directory entries to be removed
 from the FFS code. 
Thus, a large performance increase is seen in disk writing performance.

Enabling soft updates must be done with a mount-time option.
 When mounting a partition with the mount(8) utility, you can specify
 that you wish to have soft updates enabled on that partition. 
Below is a sample /etc/fstab(5) entry that has one partition sd0a 
that we wish to have mounted with soft updates.

/dev/sd0a / ffs rw,softdep 1 1
Note to sparc users: Do not enable soft updates on sun4 or sun4c machines. These architectures support only a very limited amount of kernel memory and cannot use this feature. However, sun4m machines are fine.



USBから立ち上げたOpenBSDに
pkg_add grub で grubをいれます。
openbsdにもgrubがなんとあるのです。 

そして   cat /grub/menu.lst     
  default 0
  timeout 10

 
title OpenBSD in USB
 
root (hd0,3)
 
chainloader +1

 

 
 
title slacko in USB
 
root (hd0,0)
 
kernel /slc/vmlinuz
 
initrd /slc/initrd.gz
 boot

と hd0 に気をつけてください。理由は4行先です。

 そして 
grub-instal  /dev/sd1c
をして 完成です。

つまり USBは  openbsdでは sd1 ですが、BIOSでUSBブートするので、
    (HDDは sd0 ) grub では hd0に入れ替わってますねえ~

 
 
-------------------------------------
その後本格的にこれを運用します。
porteus関係ですが 
 
bash-4.2$ ls /mnt/sda1/boot/
grub         initramfs-linux.img  vmlinuz-linux
initramfs-linux-fallback.img  syslinux
 
 
bash-4.2$ ls /mnt/sda1/porteus
base  changes  make_iso.sh  modules  optional 
porteus-v3.1-i486.sgn  rootcopy



bash-4.2$ cat /mnt/sda1/boot/syslinux/porteus.cfg LABEL --->lxqt_gui
前略 
MENU  --->LABEL Graphics mode (LXQT)
KERNEL vmlinuz
APPEND initrd=initrd.xz changes=/porteus load=003-lxqt;locales-ja
後略


です。