[英]Apache2 Ubuntu getting a cgi program to run 403 error from /usr/lib/cgi-bin
Well its 2022 and httpf.conf no longer exists.那么它的 2022 和 httpf.conf 不再存在。 its seems to be split up into site-available, and conf-available, I can't figure it out and I can't find any instructions on how to get a simple helloworld perl script to run (in runs fine from the command line" "perl hw.pl")
它似乎分为站点可用和 conf 可用,我无法弄清楚,我找不到任何关于如何运行简单的 helloworld perl 脚本的说明(从命令行运行良好" "perl hw.pl")
The index.html page works fine in firefox, and by changing the 000-default.conf I was able to at least get the script "localhost/cgi-bin/hw.pl" to change from a 404 error to a 403 error by adding the section as marked: index.html 页面在 firefox 中工作正常,并且通过更改 000-default.conf 我至少能够让脚本“localhost/cgi-bin/hw.pl”从 404 错误更改为 403 错误添加标记的部分:
leslie@jl-vr0sr4:/etc/apache2/sites-available$ pwd
/etc/apache2/sites-available
jleslie@jl-vr0sr4:/etc/apache2/sites-available$ cat 000-default.conf
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
# JL:: 221116 uncomment out the include to allow cgi-bin
# Include conf-available/serve-cgi-bin.conf
#JL:: 221116 did nothing. Lets add the below:
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
AddHandler cgi-script .pl
</Directory>
#JL:: 221116 ok, that changed the 404 not found error
# to a 403 forbidden error what gives?
# Forbidden
#
# You don't have permission to access this resource.
# Apache/2.4.52 (Ubuntu) Server at 127.0.0.1 Port 80
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
So how do I now get it to actually run?那么我现在如何让它真正运行呢?
Did I do anything make a mistake in my conf file?我有没有在我的 conf 文件中做错什么?
I also want to be able to run.exe.cgi and.sh files from /cgi-bin/ how do specify them as well?我还希望能够从 /cgi-bin/ 运行 .exe.cgi 和 .sh 文件 如何指定它们?
Here is the test hello worl perl script I tried to run:这是我尝试运行的测试 hello worl perl 脚本:
jleslie@jl-vr0sr4:/usr/lib/cgi-bin$ ll
/usr/lib/cgi-bin
total 44
drwxr-xr-x 2 root root 4096 Nov 16 09:17 ./
drwxrwxrwx 115 root root 4096 Nov 14 13:07 ../
-rwxrwxrwx 1 jleslie jleslie 30144 Nov 16 08:51 fh_fe.exe*
-rwxr-xr-x 1 root root 76 Nov 16 09:17 hw.pl*
jleslie@jl-vr0sr4:/usr/lib/cgi-bin$ cat hw.pl
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "Hello, World.";
jleslie@jl-vr0sr4:/usr/lib/cgi-bin$
OK, I finally figured it out.好的,我终于明白了。 No thanks to the apache folks who keep changing the rules and fail to document properly how do do the most basic:
不感谢 apache 的人,他们不断更改规则并且未能正确记录如何做最基本的事情:
They'll gladly spend pages talking about virtual hosts, and double nested hyper-crayon whatevers, but not the most basic setup: a webserver that can run cgi-bin programs.他们会很乐意花很多篇幅讨论虚拟主机和双嵌套超级蜡笔等等,但不是最基本的设置:一个可以运行 cgi-bin 程序的网络服务器。 Unbelievable.
难以置信的。 /end gripe.
/结束抱怨。
Anyway I edited:无论如何我编辑:
/etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/000-default.conf
with this code, to both fix and document what is necessary:使用此代码,修复和记录必要的内容:
31 # JL:: 221116 uncomment out the include to allow cgi-bin
32
33 # Include conf-available/serve-cgi-bin.conf
34
35 #JL:: 221116 did nothing. Lets add the below:
36
37
38 #ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
39 #<Directory "/usr/lib/cgi-bin">
40 ScriptAlias /cgi-bin/ /var/www/cgi-bin/
41 <Directory "/var/www/cgi-bin">
42 AllowOverride None
43 Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
44 Order allow,deny
45 Allow from all
46 AddHandler cgi-script .pl .exe .cgi .sh
47 </Directory>
48
49 #JL:: 221116 ok, that changed the 404 not found error
50 # to a 403 forbidden error what gives?
51 # Forbidden
52 #
53 # You don't have permission to access this resource.
54 # Apache/2.4.52 (Ubuntu) Server at 127.0.0.1 Port 80
55
56 # here is the fix. run this at the command line:
57
58 ### RUNME ****> cd /etc/apache2/mods-enabled
59 ### RUNME ****> sudo ln -s ../mods-available/cgi.load
60
61
62 </VirtualHost>
63
Here is the complete history (with my mistakes, don't bother with them,) of the session that fixed the issue:这是解决问题的 session 的完整历史记录(包括我的错误,不要理会它们):
1807 cd /etc/apache2/sites-available/
1808 vi 000-default.conf
1809 sudo systemctl stop apache2
1810 sudo systemctl start apache2
1811 cd ..
1812 cd conf-available/
1813 ll
1814 vi serve-cgi-bin.conf
1815 cd ../sites-available/
1816 ll
1817 vi 000-default.conf
1818 pwd
1819 cd /etc/apache2/mods-enabled
1820 sudo ln -s ../mods-available/cgi.load
1821 ll
1822 sudo systemctl stop apache2
1823 sudo systemctl start apache2
please note in the documentation the double secret "turn on cgi-bin" by making the soft link.请通过创建软链接在文档中注意双重秘密“打开 cgi-bin”。 It took me over an hour of searching on the inte.net to find that one.
我在互联网上搜索了一个多小时才找到那个。 - J
-J
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.