『總結』mini_httpd + php 構建SSL MINI WEB

來源:互聯網
上載者:User

轉自:http://bbs.chinaunix.net/thread-711979-1-1.html

一、簡介
    目的:構建小型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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.