Use experiments to quickly master Apache

Source: Internet
Author: User
Article Title: Use experiments to quickly learn about Apache on the web server. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Apache is a standard web server for most linux versions.
  
This article provides an experiment to help readers quickly master the basic configuration of Apache.
  
   [PURPOSE]
  
1. Basic installation and configuration of Apache.
  
2. Use CGI in Apache.
  
3. Basic proxy configuration.
  
   [Lab requirements]
  
1. Two interconnected RH8.0 machines.
  
2. The two machines have already configured DNS.
  
   [Experiment steps]
  
1. preparations.
  
Because the web server is closely related to DNS. Prepare for this step.
  
"Use the experiment to quickly master DNS configuration ". This article is published in the network section of linuxsir.
  
The main function that DNS can implement is to be able to parse the IP addresses of station1.exmaple1.com and server1.example1.com. If you want to implement the IP addresses in/etc/hosts, either way or not. This is not recommended here.
  
The practice in this article is more conventional. Here we specify that machine 1 is server1.example1.com, and machine 2 is:
  
Station1.example1.com. You can also change the settings.
  
2. install and configure simple Apache on machine 1.
  
1) check whether the following packages are installed,
  
Httpd
Httpd-manual
  
What is missing and what is installed.
  
2) Enable the httpd service
  
# Service httpd start
  
If it fails to be enabled, check the related logs under/var/log/httpd/. Remember to add a log similar
  
192.168.0.254 example1.com server1.
  
3) Check/etc/httpd/conf/httpd. conf for the following activities:
  
DocumentRoot/var/www/html
  
4) open it in a browser:
  
Http://server1.example1.com
  
If it is normal, you will see the Apache introduction page.
  
5) create a new directory and html file.
  
# Mkdir-p/var/www/virtual/server1.example1.com/html
# Vi/var/www/virtual/server1.example1.com/html/index.html
Server1.example1.com
  
6) edit/etc/httpd/conf/httpd. conf and append the following text to the end.
  
NameVirtualHost 192.168.0.254
  
ServerName server1.example1.com
ServerAdmin root@server1.example1.com
DocumentRoot/var/www/virtual/server1.example1.com/html
ErrorLog logs/server1.example1.com-error_log
CustomLog logs/server1.example1.com-access_log combined
  
Options Indexes Includes
  
7) Make sure that DNS can resolve your VirtualHost
  
# Host server1.example1.com
  
8) Restart httpd.
  
# Service httpd restart
  
If the startup fails, view the corresponding logs under/var/log/httpd/, which will tell you the specific error.
  
9) Can I see your own webpage in the browser?
  
Http://server1.example1.com
  
10) Can I see http://server1.example1.com on Machine 2?
  
3. Machine 1: Apply CGI in Apache
  
1) edit/etc/httpd/conf/httpd. conf and add the following line to the block:
  
ScriptAlias/cgi-bin // var/www/virtual/server1.example1.com/cgi-bin/
  
2) create a directory and a file.
  
# Mkdir/var/www/virtual/server1.example1.com/cgi-bin
# Vi/var/www/virtual/server1.example1.com/cgi-bin/test.sh
  
#! /Bin/bash
Echo Content-Type: text/html
Echo
  
Echo ""
Echo My username is:
Whoami
Echo
Echo My id I ??? S ?? ?? Success ?! S:
Id
Echo
Echo Here is/etc/passwd:
Cat/etc/passwd
Echo ""
  
3) change the execution permission of test. sh:
  
# Chmod 555 test. sh
  
4) restart the httpd service:
  
# Service httpd restart
  
If there is an error, check the log.
  
5) Browse: http://server1.example1.com/cgi-bin/test.sh
  
6) can machine 2 browse http://server1.example1.com/cgi-bin/test.sh?
  
4. Basic proxy configuration:
  
1) machine 1. Check whether the squid is packaged. If not, install it.
  
2) machine 1, start the squid service.
  
# Service squid start
  
Is there a problem? View/var/log/messages.
  
3) machine 1. Set the proxy port to 3128 in the browser. For example, in mozilla: Edit | Preferences... |
  
In Advanced | proxies, set manual, Port: 3128, and other parameters are not moved.
  
Machine 2, similar to setting in the browser: manual, http Proxy: 192.168.0.254 port: 3128.
  
4) in this case, machine 1 can browse server1.exmaple1.com.. If it can access the internet normally, it can also access the internet normally.
  
5) machine 2 cannot browse server1.example1.com or internet.
  
View the/var/log/httpd/* log file. Why?
  
6) edit/etc/squid. conf and add the following line under the acl CONNECT method CONNECT line:
  
Acl examample1 src 192.168.0.0/24
  
Locate insert your own rule (S) HERE and add the following line:
  
Http_access allow example1
  
7) Restart squid
  
# Service squid restart
  
Wrong? View logs.
  
8) in this case, machine 2 can browse the server1.example1.com or internet webpage.
  
9) edit/etc/squid. conf and add
  
Acl otherdeny dstdomain .sina.com.cn
  
Add the following in http_access allow example1:
  
Http_access deny otherdeny
  
10) Restart squid.
  
# Service squid restart
  
Wrong? View logs.
  
11) machine 2, can still browse the http://www.sina.com.cn, why?
  
12) edit/etc/squid. conf and put http_access deny otherdeny
  
Http_access allow example1 front, restart squid, machine 2 can also see
  
Http://www.sina.com.cn?
  
   [Experiment Summary]
  
Whether Apache configuration is successful has a lot to do with DNS. Therefore, the reader is required to take the time to do DNS work. This article
  
In the most popular way, we will teach you how to configure Apache in a simple way. If you want to learn more about Apache, you have to study the Apache2.0 documentation.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.