Nginx+FastCGI支持HTTPS部署过程详述

依赖的软件

nginx-1.13.5.tar.gz

spawn-fcgi-1.6.4.tar.gz

fcgi-2.4.0.tar.gz

编译安装

[[email protected] ~]# tar  xzvf nginx-1.13.5.tar.gz

[[email protected] ~]# cd  nginx-1.13.5

[[email protected] nginx-1.13.5]# ./configure --prefix=/usr/local/nginx

./configure: error: the HTTP rewrite module requires the PCRE library.

You can either disable the module by using --without-http_rewrite_module

option, or install the PCRE library into the system, or build the PCRE library

statically from the source with nginx by using --with-pcre=<path> option.

[[email protected] nginx-1.13.5]# yum  -y install prce-devel

[[email protected] nginx-1.13.5]# /usr/sbin/groupadd -f www

[[email protected] nginx-1.13.5]# /usr/sbin/useradd -g www www

[[email protected] nginx-1.13.5]# ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module

[[email protected] nginx-1.13.5]# make

[[email protected] nginx-1.13.5]# ls

auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  Makefile  man  objs  README  src

[[email protected] ]# tar   xzvf spawn-fcgi-1.6.4.tar.gz

[[email protected] spawn-fcgi-1.6.4]# ls

aclocal.m4  autom4te.cache  config.h.in    configure     depcomp     Makefile     missing      README        stamp-h1

AUTHORS     CMakeLists.txt  config.log     configure.ac  doc         Makefile.am  NEWS         spawn-fcgi.1

autogen.sh  config.h        config.status  COPYING       install-sh  Makefile.in  packdist.sh  src

[[email protected] spawn-fcgi-1.6.4]# ./autogen.sh

./autogen.sh: line 11: autoreconf: command not found

[[email protected] spawn-fcgi-1.6.4]# yum install autoconf automake libtool

[[email protected] spawn-fcgi-1.6.4]# ./autogen.sh

configure.ac:9: installing `./install-sh‘

configure.ac:9: installing `./missing‘

src/Makefile.am: installing `./depcomp‘

Now type ‘./configure ...‘ and ‘make‘ to compile.

[[email protected] spawn-fcgi-1.6.4]# ./configure

[[email protected] spawn-fcgi-1.6.4]# make

[[email protected] spawn-fcgi-1.6.4]# ls

aclocal.m4  autom4te.cache  config.h.in    configure     depcomp     Makefile     missing      README        stamp-h1

AUTHORS     CMakeLists.txt  config.log     configure.ac  doc         Makefile.am  NEWS         spawn-fcgi.1

autogen.sh  config.h        config.status  COPYING       install-sh  Makefile.in  packdist.sh  src

[[email protected] spawn-fcgi-1.6.4]# cp src/spawn-fcgi

spawn-fcgi    spawn-fcgi.c  spawn-fcgi.o

[[email protected] spawn-fcgi-1.6.4]# cp src/spawn-fcgi /usr/local/nginx/sbin/

[[email protected] ~]# tar  xzvf fcgi-2.4.0.tar.gz

[[email protected] ~]# cd fcgi-2.4.0

[[email protected] fcgi-2.4.0~]# ./configure

[[email protected] fcgi-2.4.0~]# make && make install

颁发证书

[[email protected] ~]# cd /etc/pki/tls/certs

[[email protected] certs]# make server.key

umask 77 ; \

/usr/bin/openssl genrsa -aes128 2048 > server.key

Generating RSA private key, 2048 bit long modulus

......................................................++++++

.............++++++

e is 61251 (0x10001)

Enter pass phrase: 654321 #设置密码

Verifying - Enter pass phrase: 654321

# remove passphrase from private key

[[email protected] certs]# openssl rsa -in server.key -out server.key

Enter pass phrase for server.key: 654321 #输入密码

writing RSA key

[[email protected] certs]# make server.csr

umask 77 ; \

/usr/bin/openssl req -utf8 -new -key server.key -out server.csr

You are about to be asked to enter information that will be incorporated

into your certificate request.

What you are about to enter is what is called a Distinguished Name or a DN.

There are quite a few fields but you can leave some blank

For some fields there will be a default value,

If you enter ‘.‘, the field will be left blank.

-----

Country Name (2 letter code) [XX]:CN #国家名称

State or Province Name (full name) [e]:Beijing   #州或省的名称

Locality Name (eg, city) [Default City]:Beijing  #地点名称(如城市)

Organization Name (eg, company) [Default Company Ltd]:Test   机构名称(如公司)

Organizational Unit Name (eg, section) []:Test Haha   组织单位名称(如部分)

Common Name (eg, your server‘s hostname) []:www.test.com   #常见的名字(例如,您的服务器的主机名)

Email Address []:[email protected] # 电子邮件地址

Please enter the following ‘extra‘ attributes

to be sent with your certificate request

A challenge password []:# 挑战密码

An optional company name []:#一个可选的公司名称

[[email protected] certs]#

[[email protected] certs]# openssl x509 -in server.csr -out server.crt -req -signkey server.key -days 3650

Signature ok

subject=/C=CN/ST=Beijing/L=Beijing/O=Test/OU=Test Haha/CN=www.test.com,/[email protected]

Getting Private key

[[email protected] certs]# chmod 400 server.*

[[email protected] nginx-1.13.5]# /usr/local/nginx/sbin/nginx -t

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

[[email protected] nginx-1.13.5]# /usr/local/nginx/sbin/nginx

2)可用“kill -HUP 主进程id ”命令(如:kill -HUP 1)重新加载配置文件。

3)可用“kill -QUIT 主进程id” 命令(如:kill -QUIT 1)关闭Nginx。

测试Nginx

浏览器输入:https://IP:8088/

测试FastCGI

编写了如下的测试程序test.c,代码如下:

#include <stdio.h>

#include <fcgi_stdio.h>

#include <stdlib.h>

int main()

{

int count = 0;

while (FCGI_Accept() >= 0)

{

printf("Content-type: text/html\r\n"

"\r\n"

""

"FastCGI Hello!"

"Rrunning on host [%s] Get str is [%s] "

"Process ID: [%d]\n", getenv("SERVER_NAME"),getenv("QUERY_STRING"), getpid());

}

return 0;

}

[[email protected] ~]#gcc -g -o test test.c -lfcgi

[[email protected] ~]#mv  test /usr/local/nginx/sbin/

[[email protected] ~]#/usr/local/nginx/sbin/spawn-fcgi -a 127.0.0.1 -p 9000 -f /usr/local/nginx/sbin/test -n

浏览器输入:https://IP:8088/test.cgi?abcdf

FastCGI Hello!Rrunning on host [localhost] Get str is [abcdf] Process ID: [22976]

时间: 2024-10-03 23:45:23

Nginx+FastCGI支持HTTPS部署过程详述的相关文章

nginx配置支持https和wss(websocket)协议

server { listen 80; listen 443 ssl http2; server_name lyz810.com; root /website/lyz810-main; ssl_certificate certificate/lyz810.com.crt; ssl_certificate_key certificate/lyz810.com.key; location /websocket/ { internal; if ( $http_sec_websocket_protoco

【入门篇】Nginx + FastCGI 程序(C/C++) 搭建高性能web service的Demo及部署发布

http://blog.csdn.net/allenlinrui/article/details/19419721 1.介绍 Nginx - 高性能web server,这个不用多说了,大家都知道. FastCGI程序 - 常驻型CGI程序,它是语言无关的.可伸缩架构的CGI开放扩展,其主要行为是将CGI解释器进程保持在内存中并因此获得较高的性能. Nginx要调用FastCGI程序,需要用到FastCGI进程管理程序(因为nginx不能直接执行外部的cgi程序,我们可使用lighttpd中的s

Nginx + FastCGI 程序(C/C++)搭建高性能web service的demo

http://blog.csdn.net/chdhust/article/details/42645313 Nginx + FastCGI 程序(C/C++)搭建高性能web service的Demo 1.介绍 Nginx - 高性能web server,这个不用多说了,大家都知道. FastCGI程序 - 常驻型CGI程序,它是语言无关的.可伸缩架构的CGI开放扩展,其主要行为是将CGI解释器进程保持在内存中并因此获得较高的性能. Nginx要调用FastCGI程序,需要用到FastCGI进程

Nginx FastCGI的运行原理

一.FastCGI 1.介绍 CGI全称通用网关接口 Commmon Gateway Interface 用于HTTP服务上的程序服务通信交流的一种工具,CGI程序须运行在网络服务器上. 传统CGI接口方式性能较差,由于每次HTTP服务器遇到动态程序需要重启解析器来执行解析,然后结果被返回给HTTP服务器.这在处理高并发时,几乎是不可能的,因此诞生了FastCGI.另外传统的CGI接口方式安全性也很差 一个可伸缩地.高速地在HTTP服务器和动态脚本语言间通信的接口 接口在linux下是socke

nginx fastcgi php-fpm的关系梳理

CGI(Common Gateway Interface)CGI全称是“公共网关接口”(Common Gateway Interface),HTTP服务器与你的或其它机器上的程序进行“交谈”的一种工具,其程序须运行在网络服务器上.CGI可以用任何一种语言编写,只要这种语言具有标准输入.输出和环境变量.如php,perl,tcl等. FastCGIFastCGI像是一个常驻(long-live)型的CGI,它可以一直执行着,只要激活后,不会每次都要花费时间去fork一次(这是CGI最为人诟病的fo

Nginx+FastCGI运行原理

转自  http://book.51cto.com/art/201202/314840.htm Nginx不支持对外部程序的直接调用或者解析,所有的外部程序(包括PHP)必须通过FastCGI接口来调用.FastCGI接口在Linux下是socket(这个socket可以是文件socket,也可以是ip socket).为了调用CGI程序,还需要一个FastCGI的wrapper(wrapper可以理解为用于启动另一个程序的程序),这个wrapper绑定在某个固定socket上,如端口或者文件s

十五大原理之一--Nginx FastCGI的运行原理

一.FastCGI 1.介绍 CGI全称通用网关接口 Commmon Gateway Interface 用于HTTP服务上的程序服务通信交流的一种工具,CGI程序须运行在网络服务器上. 传统CGI接口方式性能较差,由于每次HTTP服务器遇到动态程序需要重启解析器来执行解析,然后结果被返回给HTTP服务器.这在处理高并发时,几乎是不可能的,因此诞生了FastCGI.另外传统的CGI接口方式安全性也很差 一个可伸缩地.高速地在HTTP服务器和动态脚本语言间通信的接口 接口在linux下是socke

CentOS6.5 下在Nginx中添加SSL证书以支持HTTPS协议访问

参考文献: 1. NginxV1.8.0安装与配置 2. CentOS下在Nginx中添加SSL证书以支持HTTPS协议访问 3. nginx配置ssl证书的方法 4.nginx强制使用https访问(http跳转到https) 5.nginx ssl 107 (net::ERR_SSL_PROTOCOL_ERROR) 无法与服务器建立安全连接 解决方法 配置过程如下: 我的nginx是 yum 安装 具体安装过程参考:[转]CENTOS 6.5 配置YUM安装NGINX+服务器负载均衡 一.安

nginx配置免费ssl证书支持https安全访问

1.自行颁发不受浏览器信任的SSL证书: HTTPS的SSL证书可以自行颁发,Linux下的颁发步骤如下: openssl genrsa -des3 -out www.aaa.com.key 1024 openssl req -new -key www.aaa.com.key -out www.aaa.com.csr openssl rsa -in www.aaa.com.key -out www.aaa.com_nopass.key Nginx.conf的SSL证书配置,使用www.aaa.c