Install and configure ssl and C for cgi in minihttp

Source: Internet
Author: User
Tags ssl certificate

// Refer to the methods of the experts and make changes in combination with their own environment, mainly to talk about: Mini HTTP installation and configuration ssl and C language to implement cgi receiving string and save
// First, describe the environment. I used centos6.5. openssl and openssl-devel have been installed before. Here, no instructions on openssl installation are provided.
// The installation package, mini_httpd-1.19.tar.gz,
Installation of minihttp and cgi in C language, receiving strings and saving
1. tar zxf mini_httpd-1.19.tar.gz cgic206.tar.gz and openssl-devel installation packages
Cd mini_httpd-1.19
// An error will be reported if I do not modify it during installation, indicating that the original getline is in conflict with the system function.
Change vim htpasswd. c + 52 getline to my_getline.
Change vim htpasswd. c + 192 getline to my_getline.
2. make
3. make install
4. Create a directory for storing web pages and cgi:
Mkdir/root/mini/


Mkdir/root/mini/wwwroot


Mkdir/root/mini/wwwroot/cgi-bin
5. Create a configuration file
Touch/root/mini/mini_httpd.pid
Touch/root/mini/wwwroot/mini_httpd.log
 
Add the following content to vim mini/mini_httpd.conf:
Port = 8080
Dir =/root/mini/wwwroot
Cgipat = cgi-bin /*
User = nobody
Pidfile =/root/mini/mini_httpd.pid
Logfile =/root/mini/wwwroot/mini_httpd.log
6. Place the webpage in the wwwroot directory;
Touch mini/wwwroot/index.html
Echo mymini_httpd> index.html
7. Start mini_httpd:
/Usr/local/sbin/mini_httpd-C/etc/mini_httpd.conf
8. Access the mini_httpd server in the client browser, and enter
IP Address: 8080


1. Configure ssl
Edit Makefile
Remove comments from rows 17 to 20
SSL_TREE =/usr/local/ssl
SSL_DEFS =-DUSE_SSL
SSL_INC =-I $ {SSL_TREE}/include
SSL_LIBS =-L $ {SSL_TREE}/lib-lssl-lcrypto
Modify row 365 to 3650
Cert: mini_httpd.pem
Mini_httpd.pem: mini_httpd.cnf
Openssl req-new-x509-days 3650-nodes

2. make
Make install
If an error occurs, make clean is required for re-compilation.
3. generate an ssl Certificate
Make cert
Cp./mini_httpd.pem/etc/
4. Modify the mini_httpd.conf configuration file and create a new one.
# Mini_httpd configuration file
Data_dir =/root/mini/wwwroot/
# It is too critical. If no content is added before, the result is that the content cannot be written in the program.
User = root
Port = 443
Host = 0.0.0.0
Cgipat = cgi-bin/*. cgi
Logfile =/var/log/mini_httpd
Pidfile =/var/run/mini_httpd.pid
Charset = GB2312
Ssl
Certfile =/etc/mini_httpd.pem
5. Install cgic206.tar.gz
Tar zxf cgic206.tar.gz
Cd cgic206
Make
The generated is the tested. cgi program.
Write a. cgi program by yourself
Vim test. c
Source code:
# Include <stdio. h>
# Include "cgic. h"
# Include <string. h>
# Include <stdlib. h>
# Include <sys/types. h>
# Include <sys/stat. h>
# Include <fcntl. h>
# Include <unistd. h>


Extern char * cgiQueryString;


Int file_w (char * filename, char * buf)
{
Int size, fd;
Fd = open (filename, O_CREAT | O_RDWR | O_TRUNC, 0664 );
Size = write (fd, buf, strlen (buf ));
If (size <0)
{
Return-1;
}
Close (fd );
Return 0;
}


Int cgiMain (){
Int res;
Res = file_w ("/root/tang. log", cgiQueryString );
If (res =-1)
{
Perror ("file_w ");
}
# If 1
CgiHeaderContentType ("text/html ");
Fprintf (cgiOut, "<HTML> <HEAD> \ n ");
Fprintf (cgiOut, "<TITLE> My CGIC </TITLE> </HEAD> \ n ");
Fprintf (cgiOut, "<BODY> ");
Fprintf (cgiOut, "<H1> % s </H1>", cgiQueryString );
Fprintf (cgiOut, "</BODY> \ n ");
Fprintf (cgiOut, "</HTML> \ n ");
# Endif
Return 0;
}


Modify the Makefile and remember to back up the file before modification.
Cp Makefile Makefilebak
Vim Makefile
In command line mode, replace cgictest:
: % S/cgictest/test/g
 
Ps-ef | grep mini_httpd
Kill-9 process no.

Reference: http://joyquitelarge.blog.163.com/blog/static/179062171201241165644255/
Http://www.cnblogs.com/liuyangriver/archive/2012/10/31/2748576.html
Http://deepfuture.iteye.com/blog/1435339
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.