ubuntu nginx +fastcgi安装

23 篇文章 0 订阅
5 篇文章 0 订阅

nginx

准备第三方支持库源码:
nginx-1.13.7.tar.gz
openssl-1.1.0g.tar.gz
pcre-8.41.tar.gz
zlib-1.2.11.tar.gz

 cd nginx-1.13.7
./configure --prefix=/usr/local/nginx --with-http_realip_module --with-http_addition_module --with-http_gzip_static_module --with-http_secure_link_module --with-http_stub_status_module --with-stream --with-pcre=../pcre-8.41 --with-zlib=../zlib-1.2.11 --with-openssl=../openssl-1.1.0g
make && make install

启动

sudo ./sbin/nginx -c conf/nginx.conf

信号

sudo ./sbin/nginx nginx -s signal

信号(signal)的值可能是以下之一:
stop - 快速关闭服务
quit - 正常关闭服务
reload - 重新加载配置文件
reopen - 重新打开日志文件

反向代理

worker_processes 4;

events {
	worker_connections 1024;
}


http {

	upstream backend {
		server 192.168.1.2 weight=2; //负载均衡权重
		server 192.168.1.3 weight=1;
		server 192.168.1.4 weight=1;
	}

	server {
		listen 8888;
		server_name localhost;
		
		client_max_body_size 100m;
		
		location / {
			proxy_pass http://backend;
		}		

		location /images/ {
			root /usr/local/nginx/;
		}
		
		location ~ \.(mp3|mp4) {
			root /usr/local/nginx/media/;
		}		
	
	}
}

fastcgi

  • 安装fcgi.tar.gz.
  • 安装spawn-fcgi-master.zip

一个cgi程序

#include "fcgi_stdio.h"
#include <stdlib.h>

int main(void)
{
int count = 0;

while (FCGI_Accept() >= 0)
{
    printf("Content-type: text/html\r\n"
        "\r\n"
        "<title>Hello World</title>"
        "<h1>Hello World from FastCGI!</h1>"
        "Request number is: %d\n",
        ++count);
}

return 0;
}

启动cgi

./spawn-fcgi -a 127.0.0.1 -p 9002 -f /usr/local/nginx/cgi_test -n
server {
	listen 9000;
		
	location ~ \.cgi {
		fastcgi_pass 127.0.0.1:9002;
		fastcgi_index index.cgi;
		fastcgi_param SCRIPT_FILENAME cgi$fastcgi_script_name;
		include ./conf/fastcgi_params;
		}
	} 

在浏览器输入

http://192.168.1.1:9000/a.cgi
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值