我正在測試一個簡單的cgi示例,但我無法繞過權限錯誤。這裏是細節。運行二進制cgi權限錯誤
變交流
#include <stdio.h>
int main(void)
{
puts("Content-type: text/html\n");
puts("Hello, world!");
return 0;
}
與
gcc a.c
的index.html
<html>
<body>
<p>Hello, world!</p>
<a href="cgi-bin/a.out">test</a>
</body>
</html>
start-server.sh編譯
sudo python -m http.server --cgi 80
每當我點擊'測試',服務器就會抱怨權限被拒絕,這個日誌。
Serving HTTP on 0.0.0.0 port 80 (http://0.0.0.0:80/) ...
192.168.0.1 - - [24/Feb/2017 19:41:48] "GET/HTTP/1.1" 200 -
192.168.0.1 - - [24/Feb/2017 19:41:49] "GET /cgi-bin/a.out HTTP/1.1" 200 -
----------------------------------------
Exception happened during processing of request from ('192.168.0.1', 51670)
Traceback (most recent call last):
File "/usr/lib/python3.6/http/server.py", line 1126, in run_cgi
os.execve(scriptfile, args, env)
PermissionError: [Errno 13] Permission denied: '/home/mj/http/cgi-bin/a.out'
----------------------------------------
192.168.0.1 - - [24/Feb/2017 19:41:49] CGI script exit status 0x7f00
如果它的事項,爲a.out
許可是rwxr-xr-x
錯誤似乎不是關於腳本的內容,而是關於Web服務器進程用戶的訪問權限。 – dmi
@dmi好吧,那麼我如何爲用戶授予訪問權限,或者您是否說這個問題有更好的堆棧交換站點? – MinjaeKim
這不是一個C++問題**,你的CGI甚至沒有執行。 –