nginx 서버에서 CGI 프로그램 작성

WBOY
풀어 주다: 2016-08-08 09:21:38
원래의
1292명이 탐색했습니다.

Ubuntu 시스템을 사용하고 있습니다

1. nginx 서버 설치

http://nginx.org/download/nginx-1.9.2.tar.gz
tar -zvxf nginx-1.9.2.tar.gz
cd nginx
./configure
make && make install
로그인 후 복사

기본 설치 경로: /usr/local/nginx

nginx 단순 구성: / usr /local/nginx/conf/nginx.conf

#user  nobody;
worker_processes  4;

error_log  logs/error.log;
error_log  logs/error.log  notice;
error_log  logs/error.log  info;

pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  logs/access.log  main;

    sendfile        on;
    tcp_nopush      on;

    #keepalive_timeout  0;
    keepalive_timeout  90;

    #gzip  on;

    server {
        listen       192.168.88.134:8080; //修改成自己的ip地址跟端口
        server_name  192.168.88.134;

        #charset koi8-r;

        access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm index.php;
			#autoindex on;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
           root           html;
           fastcgi_pass   127.0.0.1:9999;
           fastcgi_index  index.php;
           fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
           include        fastcgi_params;
        }
        location ~ \.cgi$ {
           root           html;
           fastcgi_pass   127.0.0.1:7000;
           fastcgi_index  index.php;
           fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
           include        fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }
}
로그인 후 복사
nginx 시작:/usr/local/nginx/sbin/nginx

nginx 닫기: kill `ps aux|grep nginx|sed -n '1p'| awk '{print $2}'`

2.spawn-fcgi 설치

apt-get install apawn-fcgi
로그인 후 복사
3. fast-cgi
wget http://www.fastcgi.com/dist/fcgi.tar.gz
tar -xvzf <span style="font-family: Arial, Helvetica, sans-serif; font-size: 12px;">fcgi.tar.gz</span>
로그인 후 복사
此时不能编译安装
cd fcgi-2.4.1/include
打开fcgio.h 添加#include <stdio.h>
./configure
make && make install
로그인 후 복사
컴파일된 Spawn-fcgi를 nginx 디렉토리
cp./src에 복사합니다. /스폰-fcgi/usr/로컬/nginx/sbin/

cp/usr/로컬/lib/ libfcgi.그래서.0 /usr/lib

모든 사람이 설치한 디렉터리는 동일하지 않을 수 있습니다. , 직접 해보세요

cgi 프로그램 작성

#include <fcgi_stdio.h>
#include <iostream>
using namespace std;

int main(int argc, char *argv[])
{
    while(FCGI_Accept() >=0)
	{
		FCGI_printf( "Status: 200 OK\r\n" );
		FCGI_printf( "Content-Type: text/html\r\n\r\n" );
		FCGI_printf( "Hello world in C\n" );
	}
    return 0;
}
로그인 후 복사
컴파일:

g++ -o test.cgi test.cpp -L /usr/local/lib/ -lfcgi 
로그인 후 복사
test.cgi를 /usr/local/nginx/html/에 복사합니다.

spqwn-fcgi 프로그램 시작

spawn-fcgi -a 127.0.0.1 -p 7000 -u nobody -f ./test.cgi
로그인 후 복사
nginx에
location ~ \.cgi$ {
           root           html;
           fastcgi_pass   127.0.0.1:7000;
           fastcgi_index  index.php;
           fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
           include        fastcgi_params;
        }
로그인 후 복사
브라우저를 열고 다음을 입력하세요: http://192.168.88.134:8080/test.cgi

인쇄: Hello world in C

문서 참조:

http://wiki.ubuntu.org.cn/Nginx


http://blog.chinaunix.net/uid-30030431-id-4669581.html


http://terry831010.blog.163.com/blog/static/6916117120126185428827/





저작권 표시: 이 글은 해당 블로거의 원본 글이므로 블로거의 허락 없이 복제할 수 없습니다.

위 내용은 내용 측면을 포함하여 nginx 서버에서 cgi 프로그램을 작성하는 방법을 소개합니다. PHP 튜토리얼에 관심이 있는 친구들에게 도움이 되기를 바랍니다.

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!