我已經用C++編寫了一個程序,並使用gcc編譯了它(如fastcgi.com中的示例),但我不知道如何在本地主機上運行它。如何配置apache2和fastCGI來運行我的C++應用程序
無處不在我搜索,我發現了mod_fcgi不會工作的PHP配置 爲c + +。
是否配置了apache和mod_fcgi來運行C++ web應用程序?
我已經用C++編寫了一個程序,並使用gcc編譯了它(如fastcgi.com中的示例),但我不知道如何在本地主機上運行它。如何配置apache2和fastCGI來運行我的C++應用程序
無處不在我搜索,我發現了mod_fcgi不會工作的PHP配置 爲c + +。
是否配置了apache和mod_fcgi來運行C++ web應用程序?
mod_fcgi?我發現只有mod_fastcgi和mod_fcgid。 Apache配置對於兩者來說都很簡單。讓我們編譯的FastCGI例如,創建一個簡約的Apache實例來服務它:
安裝libfcgi-dev的
某處創建臨時目錄和編譯從https://opensource.apple.com/source/FastCGI/FastCGI-4/fcgi/doc/fcgi-devel-kit.htm#S3.1
的例子如果只是運行它,它已經有一些輸出:
$ ./tiny-cgi
Content-type: text/html
<title>FastCGI Hello!</title><h1>FastCGI Hello!</h1>Request number 1 running on host <i>(null)</i>
安裝的Apache2和中的libapache2-MOD-fcgid;創建配置文件的apache.conf:
User www-data
Listen 8080
PidFile apache.pid
DocumentRoot .
LoadModule fcgid_module /usr/lib/apache2/modules/mod_fcgid.so
SetHandler fcgid-script
Options +ExecCGI
ErrorLog error.log
用戶WWW的數據是非常重要的,因爲它可以訪問/var/lib/apache2/fcgid/sock/
,這是fcgid非常重要的(我運行Debian的,也許別的地方會有所不同)。將DocumentRoot放在與其他目錄相同的目錄中並不是很好,但這只是一個簡單的例子。
運行sudo /usr/sbin/apache2 -d . -f apache.conf -X
這-X
是調試模式,當服務器不會守護進程(不分離),這是此類打得非常得心應手。
轉到http://localhost:8080/tiny-cgi
,您將在其中看到FastCGI程序的輸出。如果不是,請參閱error.log
。再次
LoadModule fastcgi_module /usr/lib/apache2/modules/mod_fastcgi.so
SetHandler fastcgi-script
訪問http://localhost:8080/tiny-cgi
:
停止Apache,安裝中的libapache2-MOD-FastCGI的,將其替換配置中的兩行。
當我嘗試運行'sudo/usr/sbin/apache2 -d。 -f apache.conf -X'命令,我得到以下錯誤。 'AH00534:apache2:配置錯誤:未加載MPM'。爲什麼? – 2018-02-05 11:51:58
下面是我家開發PC的一個例子。這是一個在127.0.0.1:90上運行的C++ Web服務,我正在測試/調試。 「FcgidIOTimeout」被設置爲3600,所以當我用gdb(調試器)遍歷fcgi進程時,mod_fcgid不會超時等待響應。如果在調試時超時,fcgi應用程序將被終止。再往下,有一個ScriptAlias和一個目錄告訴Apache cgi文件夾的位置......「/ home/dgnorton/prj/dfi/build/src /」...這是我的項目的編譯輸出文件夾。您還需要檢查該目錄的權限。
我只在我的家庭系統上使用它進行調試。在野外使用任何這些工具之前,請閱讀Apache和mod_fcgid文檔。
Listen 90
NameVirtualHost 127.0.0.1:90
<VirtualHost 127.0.0.1:90>
ServerName www.example1.com
DocumentRoot /var/www/dfi
<IfModule fcgid_module>
FcgidIOTimeout 3600
</IfModule>
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi/ /home/dgnorton/prj/dfi/build/src/
<Directory "/home/dgnorton/src/dfi/build/src">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
你能發佈你的源代碼,配置文件,以及你如何試圖運行你的程序嗎?沒有這個信息,這是一個非常混亂和難以回答的問題。 – 2010-09-23 20:08:56