Build http server on centos7

Reference: http://www.jb51.net/article/137596.htm, the original text is excerpted as follows, and corresponding modifications have been made according to specific needs.

 

step:

1. Install httpd service

sudo yum install httpd

 

All configuration files for Apache are located in   /etc/httpd/conf  and . The website's data is located at /var/www by default   , but you can change this if you wish.  /etc/httpd/conf.d 

 

2. Configuration

The main configuration file for Apache is /etc/httpd/conf/httpd.conf. It contains many configurations that do not need to be changed in a basic installation. In fact, a simple website can be up and running with just a few changes to this file.

2.1 Listening port

The first thing to modify is the Listen configuration item, which defines the IP address and port on which Apache will listen for page requests. Now, you just need to make this website accessible locally, so use the localhost address. When done, the line should look like this:

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.

 

2.2 Website page HTML file location

The DocumentRoot configuration item specifies the location of the HTML files that make up website pages. This configuration item does not need to be changed as 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 where your 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 can be like this:

DocumentRoot"/var/mywebsite/html"

 

These are the only Apache configuration items that need to be modified to create a simple website.

 

2.3 Firewall port settings: open port 80

(1) Query the occupancy of TCP/UDP port 80:

sudo firewall-cmd --query-port=80/tcp

sudo firewall-cmd --query-port=80/udp

If the returned result is "no", it means that the port has not been opened, and the following settings are required; otherwise, skip step 2.3.

(2) Permanently open port 80 of TCP/UDP

 

sudo firewall-cmd --permanent --zone=public --add-port=80/tcp
sudo firewall-cmd --permanent --zone=public --add-port=80/udp

 

(3) Restart the firewall

 

sudo firewall-cmd --reload

 

 

3. Create.


 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324490727&siteId=291194637