Home > Article > Operation and Maintenance > How to configure apache
Installation and configuration of the Apache web server must be performed as root. Firewall configuration also needs to be performed as root. Viewing the results of the installation configuration using a browser should be done as a non-root user.
The main configuration file of Apache is /etc/httpd/conf/httpd.conf. It contains many configurations that do not need to be changed in a basic installation. In fact, just making a few changes to this file can get a simple website up and running. The file is quite large, so instead of cluttering this post with a lot of unnecessary stuff, I will only show those instructions that need to be changed.
First, take some time to familiarize yourself with the httpd.conf file. One of the reasons I like Red Hat is that its configuration file comments are very detailed. The httpd.conf file is no exception as it is well commented. You can use these comments to understand the configuration of the file.
The first thing to modify is the Listen configuration item, which defines the IP address and port where Apache will listen for page requests. Now, you just need to make this website accessible from local, so use the localhost address. When completed, the line should look like this: (LCTT Annotation: The IP address of localhost is 127.0.0.1, 80 is the port)
Listen 127.0.0.1:80
By setting this configuration item to the IP address of localhost, Apache will only Listen for connections from localhost. If you want your web server to listen for connections from a remote host, you can use the host's external IP address.
The DocumentRoot configuration item specifies the location of the HTML files that make up the website page. This configuration item does not need to be changed because it already points to the standard location. The line should look like this:
DocumentRoot "/var/www/html"
The Apache installation package will create the /var/www directory. If you want to change the location where website files are stored, use this configuration item to do so. For example, you might want to use a different name for the www directory to more clearly identify the website. This could look like this:
DocumentRoot "/var/mywebsite/html"
These are the only Apache configuration items that need to be modified to create a simple website. For this little exercise, only some modifications were made to the httpd.conf file (Listen configuration item). Other configuration items do not need to be configured for a simple web server.
Another thing to change: Open port 80 in our firewall. I use iptables[2] as my firewall, so I changed the /etc/sysconfig/iptables file to add allowing the HTTP protocol. The entire file looks like this:
# sample configuration for iptables service # you can edit this manually or use system-config-firewall # please do not ask us to add additional ports/services to this default configuration *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT -A INPUT -p icmp -j ACCEPT -A INPUT -i lo -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT -A INPUT -j REJECT --reject-with icmp-host-prohibited -A FORWARD -j REJECT --reject-with icmp-host-prohibited COMMIT
For more Apache-related technical articles, please visit the Apache Usage Tutorial column to learn!
The above is the detailed content of How to configure apache. For more information, please follow other related articles on the PHP Chinese website!