依赖的软件

nginx-1.13.5.tar.gz

spawn-fcgi-1.6.4.tar.gz

fcgi-2.4.0.tar.gz

编译安装

[root@OpenVPN-C ~]# tar  xzvf nginx-1.13.5.tar.gz

[root@OpenVPN-C ~]# cd  nginx-1.13.5

[root@OpenVPN-C 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.

[root@OpenVPN-C nginx-1.13.5]# yum  -y install prce-devel

[root@OpenVPN-C nginx-1.13.5]# /usr/sbin/groupadd -f www

[root@OpenVPN-C nginx-1.13.5]# /usr/sbin/useradd -g www www

[root@OpenVPN-C 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

[root@OpenVPN-C nginx-1.13.5]# make

[root@OpenVPN-C nginx-1.13.5]# ls

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

[root@OpenVPN-C ]# tar   xzvf spawn-fcgi-1.6.4.tar.gz

[root@OpenVPN-C 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

[root@OpenVPN-C spawn-fcgi-1.6.4]# ./autogen.sh

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

[root@OpenVPN-C spawn-fcgi-1.6.4]# yum install autoconf automake libtool

[root@OpenVPN-C 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.

[root@OpenVPN-C spawn-fcgi-1.6.4]# ./configure

[root@OpenVPN-C spawn-fcgi-1.6.4]# make

[root@OpenVPN-C 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

[root@OpenVPN-C spawn-fcgi-1.6.4]# cp src/spawn-fcgi

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

[root@OpenVPN-C spawn-fcgi-1.6.4]# cp src/spawn-fcgi /usr/local/nginx/sbin/

[root@OpenVPN-C ~]# tar  xzvf fcgi-2.4.0.tar.gz

[root@OpenVPN-C ~]# cd fcgi-2.4.0

[root@OpenVPN-C fcgi-2.4.0~]# ./configure

[root@OpenVPN-C fcgi-2.4.0~]# make && make install

颁发证书

[root@OpenVPN-C ~]# cd /etc/pki/tls/certs

[root@OpenVPN-C 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

[root@localhost certs]# openssl rsa -in server.key -out server.key

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

writing RSA key

[root@OpenVPN-C 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 []:admin@test.com # 电子邮件地址

Please enter the following 'extra' attributes

to be sent with your certificate request

A challenge password []:# 挑战密码

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

[root@OpenVPN-C certs]#

[root@OpenVPN-C 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,/emailAddress=admin@test.com

Getting Private key

[root@OpenVPN-C certs]# chmod 400 server.*

Nginx配置文件

worker_processes  2;

worker_cpu_affinity 01 10;

events {

worker_connections  1024;

}

http {

include       mime.types;

default_type  application/octet-stream;

sendfile        on;

tcp_nopush     on;

keepalive_timeout  65;

fastcgi_cache_path  /usr/local/nginx/fastcgi_cache levels=1:2 keys_zone=cache_fcgi:10m inactive=5m;

server_names_hash_bucket_size 128;

client_header_buffer_size 2k;

large_client_header_buffers 4 4k;

fastcgi_connect_timeout 300;

fastcgi_send_timeout 300;

fastcgi_read_timeout 300;

fastcgi_buffer_size 64k;

fastcgi_buffers 4 64k;

fastcgi_busy_buffers_size 128k;

fastcgi_temp_file_write_size 128k;

fastcgi_cache cache_fcgi;

fastcgi_cache_key $host$request_uri;

fastcgi_cache_valid 200 302 1h;

fastcgi_cache_valid 301 1d;

fastcgi_cache_valid any 1m;

fastcgi_cache_use_stale error  timeout invalid_header http_500;

server {

listen       8088;

server_name  localhost;

ssl on;

ssl_certificate /etc/pki/tls/certs/server.crt;

ssl_certificate_key /etc/pki/tls/certs/server.key;

ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;

ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;

ssl_prefer_server_ciphers on;

location / {

root   html;

index  index.html index.htm;

}

error_page   500 502 503 504  /50x.html;

location = /50x.html {

root   html;

}

location ~ \.cgi$ {

fastcgi_pass   127.0.0.1:9000;

fastcgi_index  index.cgi;

fastcgi_param  SCRIPT_FILENAME  $fastcgi_script_name;

include        fastcgi_params;

}

}

}

fastcgi_cache_path  /usr/local/nginx/fastcgi_cache levels=1:2 keys_zone=cache_fcgi:10m inactive=5m; #缓存路径文件,目录结构等级,关键字区域实际和非活动时间

fastcgi_connect_timeout=300; #连接到后端fastcgi超时时间

fastcgi_send_timeout=300;    #向fastcgi请求超时时间(这个指定值已经完成两次握手后向fastcgi传送请求的超时时间)

fastcgi_rend_timeout=300; #接收fastcgi应答超时时间,同理也是2次握手后

fastcgi_buffer_size=64k;   #读取fastcgi应答第一部分需要多大缓冲区,该值表示使用1个64kb的缓冲区读取应答第一部分(应答头),可以设置为fastcgi_buffers选项缓冲区大小

fastcgi_buffers 4 64k;#指定本地需要多少和多大的缓冲区来缓冲fastcgi应答请求,假设一个php或java脚本所产生页面大小为256kb,那么会为其分配4个64kb的缓冲来缓存;若页面大于256kb,那么大于的256kb的部分会缓存到fastcgi_temp指定路径中,这并非是个好办法,内存数据处理快于硬盘,一般该值应该为站点中php/java脚本所产生页面大小中间值,如果站点大部分脚本所产生的页面大小为256kb,那么可把值设置为16 16k,4 64k等

fastcgi_busy_buffers_size 128k; #默认值是fastcgi_buffer的2倍

fastcgi_temp_file_write_size 128k;#写入缓存文件使用多大的数据块,默认值是fastcgi_buffer的2倍

fastcgi_cache cache_fcgi;#开启fastcgi缓存并为其指定为TEST名称,降低cpu负载,防止502错误发生.

#应答代码缓存时间,200和302应答缓存为1个小时,301一天,其他1分钟

fastcgi_cache_valid 200 302 1h;

fastcgi_cache_valid 301 1d;

fastcgi_cache_valid any 1m;

fastcgi_cache_key $host$request_uri;定义fastcgi_cache的key,示例中就以请求的URI作为缓存的key,Nginx会取这个key的md5作为缓存文件,如果设置了缓存哈希目录,Nginx会从后往前取相应的位数做为目录

[root@OpenVPN-C 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

[root@OpenVPN-C 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;

}

[root@OpenVPN-C ~]#gcc -g -o test test.c -lfcgi

[root@OpenVPN-C ~]#mv  test /usr/local/nginx/sbin/

[root@OpenVPN-C ~]#/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?hellofcgi

FastCGI Hello!Rrunning on host [localhost] Get str is [hellofcgi] Process ID: [2645]

本文转自 Linux_woniu 51CTO博客,原文链接:http://blog.51cto.com/linuxcgi/1969112

Nginx+FastCGI支持HTTPS部署过程详述相关推荐

  1. Nginx如何支持HTTPS?手把手教会你每一步操作都贼简单,kafka和rabbitmq区别面试题

    随着我们网站用户的增多,我们会逐渐意识到HTTPS加密的重要性.在不修改现有代码的情况下,要从HTTP升级到HTTPS,让Nginx支持HTTPS是个很好的选择.今天我们来讲下如何从Nginx入手,从 ...

  2. Nginx如何支持HTTPS?手把手教贼简单!

    随着我们网站用户的增多,我们会逐渐意识到HTTPS加密的重要性.在不修改现有代码的情况下,要从HTTP升级到HTTPS,让Nginx支持HTTPS是个很好的选择.今天我们来讲下如何从Nginx入手,从 ...

  3. Python对接微信小程序V3接口进行支付,并使用uwsgi+nginx+django进行https部署

    网上找了很多教程,但是很乱很杂,并且教程资源很少且说的详细.这里就记录一下分享给大家 共分为以下几个步骤: 一.开始前准备信息 二.使用前端code获取用户的openid 三.对接小程序v3接口下单 ...

  4. centos yum方式安装nginx 并支持https

    https://www.jianshu.com/p/f5376bba4a60 转载于:https://www.cnblogs.com/falcon-fei/p/11159741.html

  5. NginX下Openssl的构建和部署数字证书,支持HTTPS

    一.安装 OpenSSL OpenSSL官网地址 wget https://www.openssl.org/source/openssl-1.0.2n.tar.gztar -zxvf openssl- ...

  6. Nginx + FastCGI 程序(C/C++) 搭建高性能web service的Demo及部署发布

    1.介绍     Nginx - 高性能web server,这个不用多说了,大家都知道.     FastCGI程序 - 常驻型CGI程序,它是语言无关的.可伸缩架构的CGI开放扩展,其主要行为是将 ...

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

    http://blog.csdn.net/allenlinrui/article/details/19419721 分类: C/C++2014-02-18 17:58 3875人阅读 评论(0) 收藏 ...

  8. 实战:Nginx + FastCGI 程序(C/C++) 搭建高性能web server

    1.介绍 Nginx - 高性能web server,这个不用多说了,大家都知道. FastCGI程序 - 常驻型CGI程序,它是语言无关的.可伸缩架构的CGI开放扩展,其主要行为是将CGI解释器进程 ...

  9. Nginx+FastCGI运行原理

    Nginx不支持对外部程序的直接调用或者解析,所有的外部程序(包括PHP)必须通过FastCGI接口来调用.FastCGI接口在Linux下是socket(这个socket可以是文件socket,也可 ...

最新文章

  1. Ansible9:条件语句【转】
  2. 庆祝法国队夺冠:用Python放一场烟花秀
  3. Linux下载交通图片数据集CityScapes Dataset
  4. 思科交换机PXE响应巨慢,甚至无响应问题
  5. 【职场】职场上给的期权是什么,重要吗?
  6. 数字几何处理作业1:编程实现三角网格上高斯曲率和平均曲率的计算编程部分
  7. 推荐 | 为科研人量身打造的公众号,都在这里啦
  8. php 未定义偏移,错误php未定义的偏移:2-3-4等
  9. 在构造函数中释放对象本身
  10. linux创建两块20G的磁盘,Linux 创建及扩展逻辑卷
  11. 百度文件下载慢怎么办?~教你百度网盘无需VIP离线下载大文件
  12. Markdown的书写方法
  13. 在华为云ECS上部署openGauss
  14. Quick #UE4 Tip (第1周 2020.12.5)
  15. 当迅雷显示“文件路径超出系统限制”时怎么办
  16. 九度OJ——1023Excel排序
  17. 超详细双系统安装指南
  18. R语言 | GEO数据库下载GSE基因芯片 以及表达矩阵和临床信息的提取
  19. 英汉词典 JaVa_Java案例_英汉字典_技术文章
  20. Symfony HttpClient教程

热门文章

  1. 几种简单的社交网站的标志按钮
  2. 用css实现模仿火狐社区的一个提示框
  3. 【vue】路由Router基础详解,带你快速入门~
  4. 红帽linux 竞争对手,为什么红帽不把CentOS当作竞争对手?
  5. centos 使用mysql_Centos下MySQL使用总结
  6. 栈的顺序存储结构、链式存储架构及其实现
  7. html表单中按钮添加超链接,JS 实现点击按钮实现超链接功能
  8. jQuery和vue 设置ajax全局请求
  9. 思科交换机的初始配置(使用telnet登录)
  10. New Chapter