首頁 後端開發 php教程 nginx伺服器下編寫cgi程式

nginx伺服器下編寫cgi程式

Aug 08, 2016 am 09:21 AM
error fastcgi index nginx quot

本人使用的是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. /usr/local/nginx/sbin/nginx 

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

2、安裝spawn-fcgi

#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;
        #}
    }
}
登入後複製
3、安裝fast-cgi
apt-get install apawn-fcgi
登入後複製
rrregi複製的編譯到nginx目錄
cp./src/spawn-fc /nginx/sbin /cp/usr/

local/ .0  / usr/lib每個人安裝的目錄未必一致,請自行搜尋按安裝的目錄進行拷貝修改

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
登入後複製
將test.cgi 拷貝到/usr/local/nginx/html/ 下

啟動spqwn-fcgi程序

#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;
}
登入後複製
在nginx.conf 添加
g++ -o test.cgi test.cpp -L /usr/local/lib/ -lfcgi 
登入後複製
打開瀏覽器輸入: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 //terry831010.blog.163.com/blog/static/6916117120126185428827/

載。 以上就介紹了nginx伺服器下編寫cgi程序,包括了方面的內容,希望對PHP教程有興趣的朋友有所幫助。

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
2 週前 By 尊渡假赌尊渡假赌尊渡假赌
倉庫:如何復興隊友
4 週前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
3 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
2 週前 By 尊渡假赌尊渡假赌尊渡假赌
倉庫:如何復興隊友
4 週前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
3 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱門文章標籤

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

index.html是什麼文件? index.html是什麼文件? Feb 19, 2024 pm 01:36 PM

index.html是什麼文件?

tomcat伺服器怎麼能讓外網訪問 tomcat伺服器怎麼能讓外網訪問 Apr 21, 2024 am 07:22 AM

tomcat伺服器怎麼能讓外網訪問

nginx啟動指令和停止指令是什麼 nginx啟動指令和停止指令是什麼 Apr 02, 2024 pm 08:45 PM

nginx啟動指令和停止指令是什麼

thinkphp怎麼運行 thinkphp怎麼運行 Apr 09, 2024 pm 05:39 PM

thinkphp怎麼運行

Welcome to nginx!怎麼解決? Welcome to nginx!怎麼解決? Apr 17, 2024 am 05:12 AM

Welcome to nginx!怎麼解決?

phpmyadmin怎麼註冊 phpmyadmin怎麼註冊 Apr 07, 2024 pm 02:45 PM

phpmyadmin怎麼註冊

nodejs專案怎麼部署到伺服器 nodejs專案怎麼部署到伺服器 Apr 21, 2024 am 04:40 AM

nodejs專案怎麼部署到伺服器

造訪網站出現nginx怎麼解決 造訪網站出現nginx怎麼解決 Apr 02, 2024 pm 08:39 PM

造訪網站出現nginx怎麼解決

See all articles