mini_httpd + PHP 构建SSL MINI WEB

一、简介
    目的:构建小型WEB站,具备SSL,解析PHP脚本(适用嵌入式环境)。
    作者:sundy 2006-3-6
      E_MAIL:hysundy@163.com
二、环境资源
    redhat 8
mini_httpd_1.19 b修改版
    php.4.4.2
三、步骤说明
    -------------------------------------------------------------   
    a.安装 php (简介 类似文章很多了 )
    解压 php.4.4.2
      #cd php.4.4.2/
      #./configure --prefix=/usr/local/php
      # make install
      安装完成后把/usr/local/src/php-4.4.2/php.ini-dist复制到/usr/local/php/lib/,并重命名为php.ini
     --------------------------------------------------------------

     --------------------------------------------------------------
     b.安装 mini_httpd-1.19
      解压 mini_httpd-1.19bhoc.tar.gz             
      #cd mini_httpd-1.19bhoc
      #vi Makefile
      修改后如下:
     
  1. # Makefile for mini_httpd

  2. # CONFIGURE: If you are using a SystemV-based operating system, such as
  3. # Solaris, you will need to uncomment this definition.
  4. #SYSV_LIBS =    -lnsl -lsocket

  5. # CONFIGURE: Some systems don't need -lcrypt, and indeed they get an
  6. # error if you try to link with it.  If you get an error about libcrypt
  7. # not found, try commenting out this definition.
  8. CRYPT_LIB =    -lcrypt

  9. # CONFIGURE: If you want to compile in support for https, uncomment these
  10. # definitions.  You will need to have already built OpenSSL, available at
  11. # http://www.openssl.org/  Make sure the SSL_TREE definition points to the
  12. # tree with your OpenSSL installation - depending on how you installed it,
  13. # it may be in /usr/local instead of /usr/local/ssl.
  14. SSL_TREE =        /usr/share/ssl
  15. SSL_DEFS =        -DUSE_SSL
  16. SSL_INC =        -I${SSL_TREE}/include
  17. SSL_LIBS =        -L${SSL_TREE}/lib -lssl -lcrypto

  18. # CONFIGURE: If you want to compile in support for PHP environment variables
  19. # (namely PHP_AUTH_USER and PHP_AUTH_PW) then uncomment the definition below.
  20. #PHP_ENV =         -DPHP_ENV

  21. # CONFIGURE: If you want to omit all IPV6 Support, uncomment the def below.
  22. #IPV6_DEFS =        -DNO_IPV6

  23. BINDIR =        /usr/local/sbin
  24. MANDIR =        /usr/local/man
  25. CC =                gcc
  26. CDEFS =                ${SSL_DEFS} ${SSL_INC} ${IPV6_DEFS} ${PHP_ENV}
  27. CFLAGS =        -O ${CDEFS}
  28. #CFLAGS =        -g ${CDEFS}
  29. LDFLAGS =        -s
  30. #LDFLAGS =        -g
  31. LDLIBS =        ${SSL_LIBS} ${SYSV_LIBS} ${CRYPT_LIB}

  32. all:                mini_httpd htpasswd

  33. mini_httpd:        mini_httpd.o match.o tdate_parse.o
  34.         ${CC} ${CFLAGS} ${LDFLAGS} mini_httpd.o match.o tdate_parse.o ${LDLIBS} -o mini_httpd

  35. mini_httpd.o:        mini_httpd.c version.h port.h match.h tdate_parse.h mime_encodings.h mime_types.h
  36.         ${CC} ${CFLAGS} -c mini_httpd.c

  37. match.o:        match.c match.h
  38.         ${CC} ${CFLAGS} -c match.c

  39. tdate_parse.o:        tdate_parse.c tdate_parse.h
  40.         ${CC} ${CFLAGS} -c tdate_parse.c

  41. mime_encodings.h: mime_encodings.txt
  42.         rm -f mime_encodings.h
  43.         sed < mime_encodings.txt > mime_encodings.h \
  44.           -e 's/#.*//' -e 's/[         ]*$$//' -e '/^$$/d' \
  45.           -e 's/[         ][         ]*/", 0, "/' -e 's/^/{ "/' -e 's/$$/", 0 },/'

  46. mime_types.h: mime_types.txt
  47.         rm -f mime_types.h
  48.         sed < mime_types.txt > mime_types.h \
  49.           -e 's/#.*//' -e 's/[         ]*$$//' -e '/^$$/d' \
  50.           -e 's/[         ][         ]*/", 0, "/' -e 's/^/{ "/' -e 's/$$/", 0 },/'


  51. htpasswd:        htpasswd.o
  52.         ${CC} ${CFLAGS} ${LDFLAGS} htpasswd.o ${CRYPT_LIB} -o htpasswd

  53. htpasswd.o:        htpasswd.c
  54.         ${CC} ${CFLAGS} -c htpasswd.c


  55. cert:                mini_httpd.pem
  56. mini_httpd.pem:        mini_httpd.cnf
  57.         openssl req -new -x509 -days 3650 -nodes -config mini_httpd.cnf -out mini_httpd.pem -keyout mini_httpd.pem
  58.         openssl x509 -subject -dates -fingerprint -noout -in mini_httpd.pem
  59.         chmod 600 mini_httpd.pem


  60. install:        all
  61.         rm -f ${BINDIR}/mini_httpd ${BINDIR}/htpasswd
  62.         -mkdir -p ${BINDIR}
  63.         cp mini_httpd htpasswd ${BINDIR}
  64.         rm -f ${MANDIR}/man8/mini_httpd.8 ${MANDIR}/man1/htpasswd.1
  65.         -mkdir -p ${MANDIR}/man8
  66.         cp mini_httpd.8 ${MANDIR}/man8
  67.         -mkdir -p ${MANDIR}/man1
  68.         cp htpasswd.1 ${MANDIR}/man1

  69. clean:
  70.         rm -f mini_httpd mime_encodings.h mime_types.h htpasswd mini_httpd.rnd *.o core core.* *.core

  71. tar:
  72.         @name=`sed -n -e '/SERVER_SOFTWARE/!d' -e 's,.*mini_httpd/,mini_httpd-,' -e 's, .*,,p' version.h` ; \
  73.           rm -rf $$name ; \
  74.           mkdir $$name ; \
  75.           tar cf - `cat FILES` | ( cd $$name ; tar xfBp - ) ; \
  76.           chmod 644 $$name/Makefile $$name/mime_encodings.txt $$name/mime_types.txt ; \
  77.           chmod 755 $$name/contrib $$name/contrib/redhat-rpm ; \
  78.           tar cf $$name.tar $$name ; \
  79.           rm -rf $$name ; \
  80.           gzip $$name.tar

  81.       
复制代码

      修改说明:
      编译支持SSL,采用redhat8 自带SSL /usr/share/ssl。
      SSL_TREE =        /usr/share/ssl
      SSL_DEFS =        -DUSE_SSL
      SSL_INC =        -I${SSL_TREE}/include
      SSL_LIBS =        -L${SSL_TREE}/lib -lssl -lcrypto
      
      修改ssl证书有效期为10年, -days 3650
      cert:                mini_httpd.pem
      mini_httpd.pem:        mini_httpd.cnf
              openssl req -new -x509 -days 3650 -nodes

      #make
      #make install
      每次重新编译前需要运行(make clean)
     --------------------------------------------------------------
      生成SSL证书:
      #make cert
      安提示输入证书信息,即在当前目录下生成证书文件mini_httpd.pem 拷贝该文件到 /etc
      #cp ./mini_httpd.pem /etc      
     --------------------------------------------------------------
     修改建立mini_httpd.conf 配置文件
     
  1.       # mini_httpd configuration file
  2.       data_dir=/usr/local/www
  3.       #user=httpd
  4.       port=443
  5.       host=0.0.0.0
  6.       cgipat=**.php
  7.       logfile=/var/log/mini_httpd
  8.       pidfile=/var/run/mini_httpd.pid
  9.       charset=GB2312
  10.       ssl
  11.       certfile=/etc/mini_httpd.pem
  12.       
复制代码

      拷贝该配置文件到 /etc目录
      #cp ./mini_httpd.conf /etc
     
     --------------------------------------------------------------
     建立php 测试脚本test.php 如下:
     
  1.       #!/usr/local/php/bin/php
  2.       <?php
  3.         phpinfo();
  4.       ?>      
  5.       
复制代码

      拷贝该脚本到,web 数据目录
      #cp ./test.php /usr/local/www
      更改文件为可执行!
      #chmod +x /usr/local/www/test.php
     --------------------------------------------------------------
     配置WEB服务网卡IP
     #ifconfig eth0 192.168.1.1 up
     启动mini_httpd
     #mini_httpd -C /etc/mini_httpd.conf

     客户端测试URL
     https://192.168.1.1/test.php

转自:http://bbs.chinaunix.net/forum.php?mod=viewthread&tid=711979
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值