Difference between revisions of "Tung httpd conf"
(→Serving Personal Home Page) |
(→Create a web script in user's home) |
||
Line 38: | Line 38: | ||
# Open a browser, and enter <code> http://hostname/~user/</code>. Your personal page should display. | # Open a browser, and enter <code> http://hostname/~user/</code>. Your personal page should display. | ||
− | ===Create a | + | ===Create a cgi script in user's home=== |
#Login as a root | #Login as a root | ||
#Edit configuration file <b><code><font color=brown >/etc/httpd/conf/httpd.conf </font></code></b>again. Add handler for .cgi and exec cgi option | #Edit configuration file <b><code><font color=brown >/etc/httpd/conf/httpd.conf </font></code></b>again. Add handler for .cgi and exec cgi option | ||
Line 46: | Line 46: | ||
#:</Directory> </code></font> | #:</Directory> </code></font> | ||
#Restart the Apache server: <b><code><font color=green >service httpd restart</font></code></b> | #Restart the Apache server: <b><code><font color=green >service httpd restart</font></code></b> | ||
− | #By default, selinux doesn't allow Apache Server to read file inside user's home. Change the default setting:<b><code><font color=green > setsebool -P httpd_enable_cgi 1</font></code></b> | + | #By default, selinux doesn't allow Apache Server to read file inside user's home. |
− | #Add context type to make script exexutable. To do that you need to add expressions for cgi file and public_html that more specific that the default expression. | + | #:Change the default setting:<b><code><font color=green > setsebool -P httpd_enable_cgi 1</font></code></b> |
+ | #Add context type to make script exexutable. To do that you need to add expressions for cgi file and public_html that more specific that the default expression <b><code><font color=purple>" /home/[^/]*/((www)|(web)|(public_html))(/.+)?" </font></code></b>. | ||
#*For public_html: <b><code><font color=green >semanage fcontext -at httpd_sys_script_exec_t "/home/[^/]*/public_html"</font></code></b> | #*For public_html: <b><code><font color=green >semanage fcontext -at httpd_sys_script_exec_t "/home/[^/]*/public_html"</font></code></b> | ||
#*For cgi files: <b><code><font color=green >semanage fcontext -at httpd_sys_script_exec_t "/home/[^/]*/public_html/.+\.cgi"</font></code></b> | #*For cgi files: <b><code><font color=green >semanage fcontext -at httpd_sys_script_exec_t "/home/[^/]*/public_html/.+\.cgi"</font></code></b> |
Revision as of 21:34, 27 July 2011
Contents
Running and Configuring Apache Server
Introduction
In this page, you are going to set up a Apache server and allow a user create his own personal web page.
Creating a Public Web Page
- Login as root user
- Configure the Apache server to start when the Fedora is booted:
chkconfig httpd on
- Start the Apache server:
service httpd start
- Create index.html in
/var/www/html/
directory, write some html code in the file - Open a browser, and enter
http://localhost
. Your page should display. - Make web page available to other hosts:
iptables -I INPUT -p tcp --dport http -j ACCEPT
Serving Personal Home Page
- Login as root user
- Edit Apache Server configuration file
/etc/httpd/conf/httpd.conf
- Inside IfModule tag, comment “UserDir disable” and uncomment “UserDir public_html”
<IfModule mod_userdir.c>
- #UserDir disable
- UserDir public_html
- </IfModule>
- Inside IfModule tag, comment “UserDir disable” and uncomment “UserDir public_html”
- Restart the Apache server:
service httpd restart
- Logout root
- Create a public_html directory inside your home directory
- Change the permission of your home directory and the public_html to read and execute for other, so that the server can access files in public_html by name. Enter follow command:
-
chmod 705 /home/user/public_html
-
chmod 705 /home/user
-
- Create index.html in public_html directory, write some html code in the file.
- Change the permission of index.htm to read only for other:
chmod 704 /home/user/public_html/index.html
- By default, selinux doesn't allow Apache Server to read file inside user's home. Change the default setting:
setsebool -P httpd_enable_homedirs 1
- Check the context of public_html and index
- By default, selinux has
context type httpd_user_content_t
for/home/[^/]*/((www)|(web)|(public_html))(/.+)?
- Confirm the context type is correct:
ls -Z public_html
- By default, selinux has
- Open a browser, and enter
http://hostname/~user/
. Your personal page should display.
Create a cgi script in user's home
- Login as a root
- Edit configuration file
/etc/httpd/conf/httpd.conf
again. Add handler for .cgi and exec cgi option<Directory /home/*/public_html>
- Options +ExecCGI
- AddHandler cgi-script .cgi
- </Directory>
- Restart the Apache server:
service httpd restart
- By default, selinux doesn't allow Apache Server to read file inside user's home.
- Change the default setting:
setsebool -P httpd_enable_cgi 1
- Change the default setting:
- Add context type to make script exexutable. To do that you need to add expressions for cgi file and public_html that more specific that the default expression
" /home/[^/]*/((www)|(web)|(public_html))(/.+)?"
.- For public_html:
semanage fcontext -at httpd_sys_script_exec_t "/home/[^/]*/public_html"
- For cgi files:
semanage fcontext -at httpd_sys_script_exec_t "/home/[^/]*/public_html/.+\.cgi"
- For non-cgi files:
semanage fcontext -at httpd_user_content_t "/home/[^/]*/public_html/.+"
- For public_html:
- Apply the context: restorecon
-vRF public_html
- Confirm the context types are correct:
ls -Z public_html
- Logout root
- Create diskfree.cgi and change its permission to executable:
chmod 705 /home/user/public_html/*.cgi
- Write lines in diskfree.cgi
- Open a browser, and enter
http://hostname/~your-user-id/diskfree.cgi
. The disk usage of your computer should be displayed.