Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Apache virtual host

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

Why do you need to use virtual hosts:

First of all, it's a host, and it has an operating system.

We also need IP addresses, but for those small sites, it is extremely wasteful. So we expect to be able to virtualize multiple hosts on one host and be able to serve many different sites

# #

Apache:

Central host: section2

Virtual host: 3

The same IP hostname is different

Www.magedu.com

Www.a.org

Definition of virtual host: first cancel the central host, that is, comment DocumentRoot

1. Writing method based on IP,Host

HOST

IP1:80

IP2:80

2. Based on port:

HOST

IP:80

IP:8080

3. Based on domain name:

*: 80

ServerName cannot be the same

# #

Specific implementation method: based on IP authentication

1. Cancel the central host # DocumentRoot

2 、 cd / etc/httpd/conf.d;;vim virtual.conf

3 、

ServerName hello.magedu.com

DocumentRoot "/ www/magedu.com"

ServerName www.a.org

DocumentRoot "/ www/a.org"

4. Httpd-t checks whether there are any grammar errors.

5. Mkdir-pv / www/ {magedu.com,a.org} create a directory

6. Cd magedu.com;; vim index.html

7. Editing

MageEdu

Magedu.com

8. Ip addr add 192.168.9.248 dev eth0 add another IP address to the host

9. Ip addr show shows

# #

Port-based authentication:

1. Add and edit the configuration file under conf.d; you will find that you already have 247 IP but the port is different.

ServerName www.b.net

DocumentRoot "/ WWW/b.net"

2. Edit the main configuration file / etc/httpd/conf/httpd.conf

Listen 80

Listen 8080

3. Edit / www/b.net/index.html

4. Restart it.

#

Name-based virtual host

0 、 vim / etc/httpd/conf/httpd.conf

1. NameVirtualHost *: 80 uncomment means all IP on port 80

3 、 vim / etc/httpd/conf/virtual

4. Add NameVirtualHost 192.168.9.248 to the first line

ServerName www.a.org

DocumentRoot "/ www/a.org"

ServerName www.b.gov

DocumentRoot "/ www/b.gov"

# 333333333

You can also customize the location and format of the specified log.

ServerName www.b.gov

DocumentRoot "/ www/b.gov"

CustomLog/var/httpd/magedu.com/access_log combined

As long as you have permission, this directory will be created automatically after restart.

# 33

Ask a.org to deny access to the address 192.168.9.226

ServerName www.a.org

DocumentRoot "/ www/a.org"

Options none

AllowOverride none

Order deny,allow

Deny from 192.168.9.226

Save httpd-t to check for syntax errors to restart

# # #

A.org needs to enter a user name and password to log in.

ServerName www.a.org

DocumentRoot "/ www/a.org"

CustomLog / var/log/httpd/a.org/access_log combined

Options none

AllowOverride authconfig

AuthType basic

AuthName "Restrict area."

AuthUserFile "/ etc/httpd/.htpasswd"

Required valid-user

Save;; httpd-t check for syntax errors

Htpasswd-c-m / etc/httpd/.htpasswd tom add tom user

Add more users and remove-c.

Htpasswd-m / etc/httpd/.htpasswd hadoop

# # #

If you access a virtual host that does not exist at all:

ServerName _ default_

DocumentRoot "/ www/default"

Mkdir / www/default

Vim / www/default/index.html

Default

Restart notice that default should be kept on top when editing.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report