Home > Article > Operation and Maintenance > How to configure apache server
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. (Recommended learning: Apache Server)
In fact, just make a few changes to this file to 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'll 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:80By 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 pages. 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 creates 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 site.
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 a few modifications were made to the httpd.conf file (the 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 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 COMMITI added a new line on the third to last line of the file that allows incoming traffic on port 80. Now I reload the iptables configuration file.
[root@testvm1 ~]# cd /etc/sysconfig/ ; iptables-restore iptables
The above is the detailed content of How to configure apache server. For more information, please follow other related articles on the PHP Chinese website!