ubuntu nginx +fastcgi安装

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

猜你喜欢

转载自blog.csdn.net/weixin_39849839/article/details/109558612