Red Hat 7 builds the httpd three modes (host-based, Port, IP)

Source: Internet
Author: User

httpd is The main program of the Apache Hypertext Transfer Protocol (HTTP) server. is designed as a stand-alone background process that establishes a pool of child processes or threads that process requests.


Yum Install httpd-y #安装httpd

Yum Install policycoreutils-python-y #安装semanage


echo "Laotang" >/var/www/html/index.html #网站的默认路径是/var/www/html, we first set up Ere page

Systemctl Restart httpd #重启服务


#防火墙允许

Firewall-cmd--permanent--add-service=http

Firewall-cmd--reload


Windows Client Test: OK

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M01/98/BC/wKiom1k_1SGAd6TcAACOJLiFihM054.jpg "title=" 18. JPG "alt=" Wkiom1k_1sgad6tcaacojlifihm054.jpg "/>


After a simple test is no problem, we go directly to the topic and configure the IP-based (multi-IP) first. Allow different IP access to different home pages.


#配置子IP (restart will fail)

Ifconfig eno16777736:0 192.168.23.21 netmask 255.255.255.0 up

ifconfig eno16777736:1 192.168.23.22 netmask 255.255.255.0 up

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M01/98/BC/wKiom1k_1kjSaaWBAAFjiJXFwaE150.jpg "title=" 19. JPG "alt=" Wkiom1k_1kjsaawbaafjijxfwae150.jpg "/>


#设置每个IP的不同首页

Cd/var/www/html

RM-RF index.html #删除前面测试的首页

mkdir 20

mkdir 21

mkdir 22

echo "ip:192.168.23.20" >/var/www/html/20/index.html

echo "ip:192.168.23.21" >/var/www/html/21/index.html

echo "ip:192.168.23.22" >/var/www/html/22/index.html


Vim/etc/httpd/conf/httpd.conf #进入主配置文件, add as content at the bottom

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M00/98/BD/wKiom1k_22zBbbqKAAF1q4zNUCs856.jpg "title=" 20. JPG "alt=" Wkiom1k_22zbbbqkaaf1q4znucs856.jpg "/>


Explain:

<virtualhost 192.168.23.20 >

Documentroot/var/www/html/20 #DocumentRoot: The root directory of your document.

ServerName www.laotang6.com #ServerName指定Apache用于识别自身的名字和端口号

<Directory/var/www/html/20>

allowoverride none #AllowOverride它可以是 "All", "none".

Require all granted #允许所有请求访问资源. Require all denied deny all requests to access resources

</Directory>

</VirtualHost>


Systemctl Restart httpd #重启服务


Client test: OK

650) this.width=650; "src=" https://s2.51cto.com/wyfs02/M00/98/BD/wKiom1k_3RDibSi4AACYhNJSDUU875.jpg "style=" float : none; "title=" 21.JPG "alt=" Wkiom1k_3rdibsi4aacyhnjsduu875.jpg "/>

650) this.width=650; "src=" https://s2.51cto.com/wyfs02/M01/98/BD/wKiom1k_3RGQV3PsAACj5ZcDvBk398.jpg "style=" float : none; "title=" 22.JPG "alt=" Wkiom1k_3rgqv3psaacj5zcdvbk398.jpg "/>

650) this.width=650; "src=" https://s2.51cto.com/wyfs02/M01/98/BD/wKioL1k_3RHx1fqyAAChfcJqw9c023.jpg "style=" float : none; "title=" 23.JPG "alt=" Wkiol1k_3rhx1fqyaachfcjqw9c023.jpg "/>


Based on the IP address has been tested successfully, now to experiment based on host name, so that different host name access to different home.

Based on host name, DNS resolution is required, DNS parsing we're not going to say it here. If you do not know how to configure the words, please look at my previous configuration DNS service. http://laotang6.blog.51cto.com/12692658/1934790


Cd/var/www/html

mkdir AAA

mkdir BBB

mkdir CCC

echo "aaa.laotang6.com" >/var/www/html/aaa/index.html

echo "bbb.laotang6.com" >/var/www/html/bbb/index.html

echo "ccc.laotang6.com" >/var/www/html/ccc/index.html


DNS resolution

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M01/98/BD/wKiom1k_33qhYln2AABpmNWa0No522.jpg "title=" 24. JPG "alt=" Wkiom1k_33qhyln2aabpmnwa0no522.jpg "/>


Vim/etc/httpd/conf/httpd.conf go to the main profile and add the content as below

(in order to not affect the experiment, it is recommended to comment out the preceding IP-based configuration with #.) )

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M02/98/BD/wKioL1k_4VCz5_riAADIjSBPuFQ439.jpg "title=" 25. JPG "alt=" Wkiol1k_4vcz5_riaadijsbpufq439.jpg "/>


Systemctl Restart httpd #重启服务


Client test: OK (Note: Client DNS to point to server IP for normal parsing)

650) this.width=650; "src=" https://s2.51cto.com/wyfs02/M01/98/BE/wKioL1k_4j2xIZRaAACgBvRRqY8088.jpg "style=" float : none; "title=" 26.JPG "alt=" Wkiol1k_4j2xizraaacgbvrrqy8088.jpg "/>

650) this.width=650; "src=" https://s3.51cto.com/wyfs02/M02/98/BE/wKiom1k_4j7AS35FAACbpbGwyGQ290.jpg "style=" float : none; "title=" 27.JPG "alt=" Wkiom1k_4j7as35faacbpbgwygq290.jpg "/>

650) this.width=650; "src=" https://s3.51cto.com/wyfs02/M00/98/BE/wKiom1k_4j_DNhzKAACRAkbQzGE871.jpg "style=" float : none; "title=" 28.JPG "alt=" Wkiom1k_4j_dnhzkaacrakbqzge871.jpg "/>



Based on the host name has been tested successfully, now to experiment based on the port, so that different ports access to different home pages.

(in order to not affect the experiment, it is recommended to comment out the previous hostname configuration with #.) )

Cd/var/www/html

MKDIR 6000

mkdir 6001

mkdir 6002

echo "ip:192.168.23.20:6000" >/var/www/html/6000/index.html

echo "ip:192.168.23.20:6001" >/var/www/html/6001/index.html

echo "ip:192.168.23.20:6002" >/var/www/html/6002/index.html


vim/etc/httpd/conf/httpd.conf into the master profile, add our ports under 42 lines,

File Open Line number command (set NU)

650) this.width=650; "src=" https://s1.51cto.com/wyfs02/M02/98/DA/wKioL1lBFcCDYrPhAABH9JB99d0484.jpg "title=" 30. JPG "alt=" Wkiol1lbfccdyrphaabh9jb99d0484.jpg "/>


Then add our configuration file at the bottom

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M02/98/DA/wKioL1lBFOqzry_4AADerrrk4HQ416.jpg "title=" 29. JPG "alt=" Wkiol1lbfoqzry_4aaderrrk4hq416.jpg "/>


Then update the service (systemctl restart httpd ) and find that the update is not

650) this.width=650; "src=" https://s1.51cto.com/wyfs02/M02/98/DA/wKioL1lBFoGjmsfiAABpcJDOOcg341.jpg "title=" 31. JPG "alt=" Wkiol1lbfogjmsfiaabpcjdoocg341.jpg "/>

The reason is that the HTTP service port number in our SELinux system is not 6000 6001 6002. We'll just add the entry.

Semanage port-a-T http_port_t-p TCP 6000

Semanage port-a-t http_port_t-p TCP 6001

Semanage port-a-t http_port_t-p TCP 6002


semanage port-l | grep http #查看SElinux的http服务端口号, after the addition is complete, you can start the

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M00/98/DB/wKiom1lBF1jBRhHgAABq-_zDiDA665.jpg "title=" 32. JPG "alt=" Wkiom1lbf1jbrhhgaabq-_zdida665.jpg "/>

Systemctl Restart httpd #重启服务


Client Test OK

650) this.width=650; "src=" https://s1.51cto.com/wyfs02/M00/98/DA/wKioL1lBGDqhWFgHAACjqEgRNUs849.jpg "style=" float : none; "title=" 33.JPG "alt=" Wkiol1lbgdqhwfghaacjqegrnus849.jpg "/>

650) this.width=650; "src=" https://s1.51cto.com/wyfs02/M01/98/DA/wKioL1lBGDrRYsXFAAChXIug66o394.jpg "style=" float : none; "title=" 34.JPG "alt=" Wkiol1lbgdrrysxfaachxiug66o394.jpg "/>

650) this.width=650; "src=" https://s5.51cto.com/wyfs02/M01/98/DB/wKiom1lBGDuhrPp2AACbQ8noxbQ338.jpg "style=" float : none; "title=" 35.JPG "alt=" Wkiom1lbgduhrpp2aacbq8noxbq338.jpg "/>


The above basic configuration is complete, next we talk about the page encryption, if I configured above the three home page, there is a need to encrypt, how to set it: Example: Port 6002 of the first page needs to be encrypted.

vim/etc/httpd/conf/httpd.conf access to the master configuration file

Modify the first page of Port 6002 as follows

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M02/98/DB/wKiom1lBGc3C4HWsAABhcyLsovU136.jpg "title=" 36. JPG "alt=" Wkiom1lbgc3c4hwsaabhcylsovu136.jpg "/>


The added four lines are path, hint, encryption method, user authentication, which Tang is the system user, note: The encryption password is not the system user password.

htpasswd-c/etc/httpd/passwd Tang #设置密码 (-c parameter for first generation)


Client Testing

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M02/98/DB/wKiom1lBGvnj5HghAADP5ega5VE078.jpg "title=" 37. JPG "alt=" Wkiom1lbgvnj5hghaadp5ega5ve078.jpg "/>


After entering the correct password, display the first page

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M02/98/DB/wKioL1lBGzej75mgAACqzP0FSkY946.jpg "title=" 38. JPG "alt=" Wkiol1lbgzej75mgaacqzp0fsky946.jpg "/>






This article refers to the v0.2 version of Linux as it should be.

This article is from the "Old Tang" blog, please be sure to keep this source http://laotang6.blog.51cto.com/12692658/1936821

Red Hat 7 builds the httpd three modes (host-based, Port, IP)

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.