Cgi app — различия между версиями
Материал из pNp Wiki
Andy (обсуждение | вклад) (→Конфигурирование CGI) |
Andy (обсуждение | вклад) (→Конфигурирование CGI) |
||
| Строка 22: | Строка 22: | ||
drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_content_t:s0 private | drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_content_t:s0 private | ||
[root@vm-01 ~]# | [root@vm-01 ~]# | ||
| + | </syntaxhighlight> | ||
| + | Добавим директорию <code>/content/dynamic</code> в файле <code>/etc/httpd/conf.d/vm-01.conf</code> и укажем вебсерверу, что следует запускать файлы определенного расширения: | ||
| + | <syntaxhighlight lang="bash"> | ||
| + | # Virtual Hosts | ||
| + | # | ||
| + | # Required modules: mod_log_config | ||
| + | |||
| + | # If you want to maintain multiple domains/hostnames on your | ||
| + | # machine you can setup VirtualHost containers for them. Most configurations | ||
| + | # use only name-based virtual hosts so the server doesn't need to worry about | ||
| + | # IP addresses. This is indicated by the asterisks in the directives below. | ||
| + | # | ||
| + | # Please see the documentation at | ||
| + | # <URL:http://httpd.apache.org/docs/2.4/vhosts/> | ||
| + | # for further details before you try to setup virtual hosts. | ||
| + | # | ||
| + | # You may use the command line option '-S' to verify your virtual host | ||
| + | # configuration. | ||
| + | |||
| + | # | ||
| + | # VirtualHost example: | ||
| + | # Almost any Apache directive may go into a VirtualHost container. | ||
| + | # The first VirtualHost section is used for all requests that do not | ||
| + | # match a ServerName or ServerAlias in any <VirtualHost> block. | ||
| + | # | ||
| + | <VirtualHost *:80> | ||
| + | ServerAdmin webmaster@vm-01.example.com | ||
| + | DocumentRoot "/content" | ||
| + | ServerName vm-01.example.com | ||
| + | ServerAlias www.vm-01.example.com | ||
| + | ErrorLog "/var/log/httpd/vm-01.example.com-error_log" | ||
| + | CustomLog "/var/log/httpd/vm-01.example.com-access_log" common | ||
| + | <Directory "/content"> | ||
| + | AllowOverride None | ||
| + | # Allow open access: | ||
| + | Require all granted | ||
| + | </Directory> | ||
| + | <Directory "/content/private"> | ||
| + | AuthType basic | ||
| + | AuthName "Private area! Restricted access" | ||
| + | AuthUserFile "/etc/httpd/passwd" | ||
| + | Require valid-user | ||
| + | </Directory> | ||
| + | <Directory "/content/dynamic"> | ||
| + | Options ExecCGI | ||
| + | AddHandler cgi-script .cgi | ||
| + | </Directory> | ||
| + | </VirtualHost> | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Версия 16:54, 24 января 2018
Содержание
Конфигурирование Apache. Развертывание приложений CGI
Предварительные требования
- Виртуальная машина с двумя сетевыми интерфейсами
- Установленные пакеты:
bash-completion,policycoreutils,policycoreutils-python,policycoreutils-devel,setroubleshoot-server,httpd,httpd-manual,elinks,curl,perl
Общая информация и терминология
CGI (Common Gateway Interface) - общий интерфейс маршрутизации. Служит для взаимодействия внешних программ с вебсервером. Упрощенным языком - возможность вызова вебсервером сторонних программ и получения их результатов для дальнейшей обработки. Ранее использовался для создания динамическийх сайтов. RFC 3875
Конфигурирование CGI
Создадим директорию /content/dynamic и присвоим ей соответствующий контекст:
[root@vm-01 ~]# mkdir /content/dynamic
[root@vm-01 ~]# semanage fcontext -at httpd_sys_script_exec_t "/content/dynamic(/.*)?"
[root@vm-01 ~]# restorecon -vR /content/dynamic/
restorecon reset /content/dynamic context unconfined_u:object_r:httpd_sys_content_t:s0->unconfined_u:object_r:httpd_sys_script_exec_t:s0
[root@vm-01 ~]# ls -lahiZ /content/
drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_content_t:s0 .
dr-xr-xr-x. root root system_u:object_r:root_t:s0 ..
drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_script_exec_t:s0 dynamic
-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 index.html
drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_content_t:s0 private
[root@vm-01 ~]#Добавим директорию /content/dynamic в файле /etc/httpd/conf.d/vm-01.conf и укажем вебсерверу, что следует запускать файлы определенного расширения:
# Virtual Hosts
#
# Required modules: mod_log_config
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
ServerAdmin webmaster@vm-01.example.com
DocumentRoot "/content"
ServerName vm-01.example.com
ServerAlias www.vm-01.example.com
ErrorLog "/var/log/httpd/vm-01.example.com-error_log"
CustomLog "/var/log/httpd/vm-01.example.com-access_log" common
<Directory "/content">
AllowOverride None
# Allow open access:
Require all granted
</Directory>
<Directory "/content/private">
AuthType basic
AuthName "Private area! Restricted access"
AuthUserFile "/etc/httpd/passwd"
Require valid-user
</Directory>
<Directory "/content/dynamic">
Options ExecCGI
AddHandler cgi-script .cgi
</Directory>
</VirtualHost>