This document attempts to answer the commonly-asked questions about setting upvirtual hosts. These scenarios are those involving multiple web sites running on a single server, vianame-basedorIP-basedvirtual hosts.
Running several name-based web sites on a single IP address.
Your server has multiple hostnames that resolve to a single address, and you want to respond differently forwww.example.comandwww.example.org.
Note
Creating virtual host configurations on your Apache server does not magically cause DNS entries to be created for those host names. Youmusthave the names in DNS, resolving to your IP address, or nobody else will be able to see your web site. You can put entries in yourhostsfile for local testing, but that will work only from the machine with thosehostsentries.
# Ensure that Apache listens on port 80 Listen 80
<VirtualHost *:80>
DocumentRoot "/www/example1"
ServerName www.example.com
# Other directives here
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/www/example2" ServerName www.example.org
# Other directives here
</VirtualHost>
The asterisks match all addresses, so the main server serves no requests. Due to the fact that the virtual host with ServerName www.example.comis first in the configuration file, it has the highest priority and can be seen as thedefaultorprimaryserver. That means that if a request is received that does not match one of the specifiedServerNamedirectives, it will be served by this first<VirtualHost>.
The above configuration is what you will want to use in almost all name-based virtual hosting situations. The only thing that this configuration will not work for, in fact, is when you are serving different content based on differing IP addresses or ports.
Note
You may replace*with a specific IP address on the system. Such virtual hosts will only be used for HTTP requests received on connection to the specified IP address.
However, it is additionally useful to use*on systems where the IP address is not predictable - for example if you have a dynamic IP address with your ISP, and you are using some variety of dynamic DNS solution. Since*matches any IP address, this configuration would work without changes whenever your IP address changes.
Name-based hosts on more than one IP address.
Note
Any of the techniques discussed here can be extended to any number of IP addresses.
The server has two IP addresses. On one (172.20.30.40), we will serve the "main" server,server.example.comand on the other (172.20.30.50), we will serve two or more virtual hosts.
Listen 80
# This is the "main" server running on 172.20.30.40
ServerName server.example.com
DocumentRoot "/www/mainserver"
<VirtualHost 172.20.30.50>
DocumentRoot "/www/example1"
ServerName www.example.com
# Other directives here ...
</VirtualHost>
<VirtualHost 172.20.30.50>
DocumentRoot "/www/example2"
ServerName www.example.org
# Other directives here ...
</VirtualHost>
Any request to an address other than172.20.30.50will be served from the main server. A request to172.20.30.50with an unknown hostname, or noHost:header, will be served fromwww.example.com.
Serving the same content on different IP addresses (such as an internal and external address).
The server machine has two IP addresses (192.168.1.1and172.20.30.40). The machine is sitting between an internal (intranet) network and an external (internet) network. Outside of the network, the nameserver.example.comresolves to the external address (172.20.30.40), but inside the network, that same name resolves to the internal address (192.168.1.1).
The server can be made to respond to internal and external requests with the same content, with just one<VirtualHost>section.
<VirtualHost 192.168.1.1 172.20.30.40>
DocumentRoot "/www/server1"
ServerName server.example.com
ServerAlias server
</VirtualHost>
Now requests from both networks will be served from the same<VirtualHost>.
Note:
On the internal network, one can just use the nameserverrather than the fully qualified host nameserver.example.com.
Note also that, in the above example, you can replace the list of IP addresses with*, which will cause the server to respond the same on all addresses.
Running different sites on different ports.
You have multiple domains going to the same IP and also want to serve multiple ports. The example below illustrates that the name-matching takes place after the best matching IP address and port combination is determined.
Requests for any address not specified in one of the<VirtualHost>directives (such aslocalhost, for example) will go to the main server, if there is one.
Mixed port-based and ip-based virtual hosts
The server machine has two IP addresses (172.20.30.40and172.20.30.50) which resolve to the nameswww.example.comandwww.example.orgrespectively. In each case, we want to run hosts on ports 80 and 8080.
The following example allows a front-end machine to proxy a virtual host through to a server running on another machine. In the example, a virtual host of the same name is configured on a machine at192.168.111.2. TheProxyPreserveHost Ondirective is used so that the desired hostname is passed through, in case we are proxying multiple hostnames to a single machine.
Using such a default vhost with a wildcard port effectively prevents any request going to the main server.
A default vhost never serves a request that was sent to an address/port that is used for name-based vhosts. If the request contained an unknown or noHost:header it is always served from the primary name-based vhost (the vhost for that address/port appearing first in the configuration file).
You can useAliasMatchorRewriteRuleto rewrite any request to a single information page (or script).
_default_vhosts for different ports
Same as setup 1, but the server listens on several ports and we want to use a second_default_vhost for port 80.
The default vhost for port 80 (whichmustappear before any default vhost with a wildcard port) catches all requests that were sent to an unspecified IP address. The main server is never used to serve a request.
_default_vhosts for one port
We want to have a default vhost for port 80, but no other default vhosts.
A request to an unspecified address on port 80 is served from the default vhost. Any other request to an unspecified address and port is served from the main server.
Any use of*in a virtual host declaration will have higher precedence than_default_.
Migrating a name-based vhost to an IP-based vhost
The name-based vhost with the hostnamewww.example.org(from ourname-basedexample, setup 2) should get its own IP address. To avoid problems with name servers or proxies who cached the old IP address for the name-based vhost we want to provide both variants during a migration phase.
The solution is easy, because we can simply add the new IP address (172.20.30.50) to theVirtualHostdirective.
The vhost can now be accessed through the new address (as an IP-based vhost) and through the old address (as a name-based vhost).
Using theServerPathdirective
We have a server with two name-based vhosts. In order to match the correct virtual host a client must send the correctHost:header. Old HTTP/1.0 clients do not send such a header and Apache has no clue what vhost the client tried to reach (and serves the request from the primary vhost). To provide as much backward compatibility as possible we create a primary vhost which returns a single page containing links with an URL prefix to the name-based virtual hosts.
Due to theServerPathdirective a request to the URLhttp://www.sub1.domain.tld/sub1/isalwaysserved from the sub1-vhost. A request to the URLhttp://www.sub1.domain.tld/is only served from the sub1-vhost if the client sent a correctHost:header. If noHost:header is sent the client gets the information page from the primary host.
Please note that there is one oddity: A request tohttp://www.sub2.domain.tld/sub1/is also served from the sub1-vhost if the client sent noHost:header.
TheRewriteRuledirectives are used to make sure that a client which sent a correctHost:header can use both URL variants,i.e., with or without URL prefix.
About a week ago, when restarting apache using ssh, I got the following notice: "AH00548: NameVirtualHost has no effect and will be removed in the next release..." Same issue seen in this post: NameVirtualHost has no effect error?
I ran the rebuild mentioned in that post, and also rebuilt the EA4 profile, the notice disappeared for couple of days, then came back!
Any easy way to stop these residual NameVirtualHost entries from regenerating?
Can you open your httpd.conf file and check if the entry for Virtualhost is : <VirtualHost xxx.xx.xxx.xx:80> where (xxx is your IP ) try to replace it with : <VirtualHost *:80> and restart apache. Check if that solved the problem.
Thanks for suggestion. For some reason only one virtual host had the NameVirtualHost entry stuck. I resaved that domain's zone, and ran/scripts/rebuildhttpdconf- the NameVirtualHost entry has disappeared again, and hopefully will stay like that.
The "NameVirtualHost has no effect and will be removed in the next release" message is informational and will not result in any issues accessing your websites. It's no longer used as of cPanel version 68:
Fixed case CPANEL-15364: Avoid adding NameVirtualHost to httpd.conf when using EA4.
1) user created that has remote access for example user@'x.x.x.x'
2) there is a connection from the two machine ( they can ping each other for example or access each another by another method) the port is opened between the two machine
3) in my.ini/my.cnf there is blocking connection parameter like:bind-address=a.a.a.a or skip-networking
4) the service is up and running when you try to connect from the other machine
I had to handle high traffic loads in my career and I fought with down-time, not used memory and a lot of trouble in my past. In this article I want to give a step-by-step guide to apache2 performance settings, which is a concentrated result of a lot of reading and trying.
Precalculation of average memory usage and maxclients/max-children
1. Calculate process size
You need to know how many processes can run on your machine. So calculate the process size of your main CPU/memory drivers is necessary.
There are several calculation methods out there. Personally I prefer this python script as it takes shared memory into account and will give insights into real memory usage.
Here you can see that there are 30 apache2 processes, consuming a total of 352 MiB, so each Apache process is using roughly 12MiB of RAM. The php-fpm5.6 process will use about 50MiB.
2. Calculate apache MaxRequestWorkers
To be safe though, I’ll reserve 15% of memory for all other processes (in my case ~1,2GiB) and round up apache process size to 15MiB.
MaxRequestWorkers = (Total RAM - Memory used for Linux, DB, etc.) / process size MaxRequestWorkers = (8192MB - 1200MB) / 15MB = 466
3. Calculate php-fpm max-children
To be safe though, I’ll reserve 1 GiB for all other processes and round up php process size to 55MiB.
maxclients = (Total RAM - Memory used for Linux, DB, etc.) / process size maxclients = (8048MB - 1024MB) / 55MB = 128
Save your settings and restart your apache and php-fpm processes
sudo service apache2 restart sudo service php7.1-fpm restart
Test you settings
To test your server settings you can run Apache Bench tests and see how your server behaves in htop .
Open 2 terminals and the following command to test 5000 requests with a concurrency of 100 parallel requests:
ab -n 5000 -c 100
Load test using apache bench
I hope this helps. Drop me a line, when you have other experience or think I might can improve my formular/calculation. As well I might create a simple web-interface to calculate the settings… But now I have to go back to work ;-)
htop is a Linux process monitoring tool, It is an alternative tool for top command, Which is the standard and the default process Monitoring tool in Linux and Unix Operating System. But htop on CentOS 7 is more user friendly and output is easy to read compared to the Linux top command.
In this Tutorial We are going to learn how to Install htop on CentOS 7 using yum install command with epel repository.
To Install htop on CentOS 7 We Want to add CentOS epel repository, Because the htop software package does not come with Default CentOS yum repository.
Now we can install CentOS htop using yum install command.
yum -y install htop
Now to start htop program, Open Linux Terminal and type htop
You can see the output of the htop process monitoring tools is more readable and easy understand.
Summary : htop CentOS 7
In this tutorial we installed htop on Linux CentOS 7 using epel repository.
First, we enable the epel-release and then install htop using yum command (Without epel-release you will receive the following error "No package htop available").
We can also use this same method to install htop on CentOS 6.5 and older versions.
ab 프로그램은 웹 서버를 벤치마크하기 위해 Apache 웹 서버와 함께 제공됩니다. Watson™ Explorer Engine은 일반적으로 웹 서버 내에서 CGI 실행 파일로 실행되므로 웹 서버의 작동 성능을 파악하는 것이 유용합니다. ab 애플리케이션은 현재 Apache 설치의 작동 성능에 대한 정보를 제공하도록 설계되었으며, Apache 설치가 서비스할 수 있는 초당 요청 수를 요약해서 보여줍니다.
이 정보는 Watson Explorer Engine이 실행 중인 상태에서 Watson Explorer Engine과 독립적으로 웹 서버에서 처리할 수 있는 최대 로드를 판별하는 데 유용합니다. ab 애플리케이션은 Watson Explorer Engine이 실행 중인 동안 웹 서버를 테스트할 수 있으므로 일반 사용자 관점에서 전체 애플리케이션의 성능에 대한 정확한 벤치마크를 가져올 수 있습니다.
ab 애플리케이션은 Apache 설치 패키지의 일부로 설치됩니다. 대부분의 Linux 배포에서 이 애플리케이션은 httpd-tools 패키지에 포함되어 있습니다. ab유틸리티를 확보하는 방법에 대한 정보는 사용 중인 운영 체제에 대한 Apache 문서를 참조하십시오.
다음은 ab 애플리케이션에서 제공하는 도움말 정보입니다.
# ab -h
Usage: ab [options] [http[s]://]hostname[:port]/path
Options are:
-n requests Number of requests to perform
-c concurrency Number of multiple requests to make
-t timelimit Seconds to max. wait for responses
-b windowsize Size of TCP send/receive buffer, in bytes
-p postfile File containing data to POST. Remember also to set -T
-u putfile File containing data to PUT. Remember also to set -T
-T content-type Content-type header for POSTing, eg.
'application/x-www-form-urlencoded'
Default is 'text/plain'
-v verbosity How much troubleshooting info to print
-w Print out results in HTML tables
-i Use HEAD instead of GET
-x attributes String to insert as table attributes
-y attributes String to insert as tr attributes
-z attributes String to insert as td or th attributes
-C attribute Add cookie, eg. 'Apache=1234. (repeatable)
-H attribute Add Arbitrary header line, eg. 'Accept-Encoding: gzip'
Inserted after all normal header lines. (repeatable)
-A attribute Add Basic WWW Authentication, the attributes
are a colon separated username and password.
-P attribute Add Basic Proxy Authentication, the attributes
are a colon separated username and password.
-X proxy:port Proxyserver and port number to use
-V Print version number and exit
-k Use HTTP KeepAlive feature
-d Do not show percentiles served table.
-S Do not show confidence estimators and warnings.
-g filename Output collected data to gnuplot format file.
-e filename Output CSV file with percentages served
-r Don't exit on socket receive errors.
-h Display usage information (this message)
-Z ciphersuite Specify SSL/TLS cipher suite (See openssl ciphers)
-f protocol Specify SSL/TLS protocol (SSL2, SSL3, TLS1, or ALL)
Watson Explorer Engine 설치에 대한 로드 테스트 방법의 예제는 다음과 같습니다.
# ab -n 1000 -c 10 http://localhost/velocity/cgi-bin/query-meta
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests
Server Software: Apache/2.2.15
Server Hostname: localhost
Server Port: 80
Document Path: /velocity/cgi-bin/query-meta
Document Length: 140256 bytes
Concurrency Level: 10
Time taken for tests: 55.911 seconds
Complete requests: 1000
Failed requests: 65
(Connect: 0, Receive: 0, Length: 65, Exceptions: 0)
Write errors: 0
Total transferred: 140402934 bytes
HTML transferred: 140255934 bytes
Requests per second: 17.89 [#/sec] (mean)
Time per request: 559.107 [ms] (mean)
Time per request: 55.911 [ms] (mean, across all concurrent requests)
Transfer rate: 2452.35 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 1
Processing: 366 558 104.9 541 1350
Waiting: 353 528 104.5 511 1320
Total: 366 558 104.9 541 1350
Percentage of the requests served within a certain time (ms)
50% 541
66% 570
75% 593
80% 605
90% 650
95% 701
98% 941
99% 1059
100% 1350 (longest request)
위의 테스트는 이 Watson Explorer Engine 인스턴스를 실행하는 서버가 초당 17.89개의 요청을 처리할 수 있음을 나타냅니다. 이 결과는 query-meta를 실행하고 example-metadata 콜렉션을 검색하는 기본 구성으로 얻은 결과입니다.
meta-searching 및 검색 콜렉션을 사용한 검색에 대한 로드 테스트 출력은 다음과 같습니다.
# ab -n 100 -c 10 "http://localhost/velocity/cgi-bin/query-meta?v:project=query-meta&query=news"
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient).....done
Server Software: Apache/2.2.15
Server Hostname: localhost
Server Port: 80
Document Path: /velocity/cgi-bin/query-meta?v:project=query-meta&query=news
Document Length: 124894 bytes
Concurrency Level: 10
Time taken for tests: 70.536 seconds
Complete requests: 100
Failed requests: 99
(Connect: 0, Receive: 0, Length: 99, Exceptions: 0)
Write errors: 0
Total transferred: 12478129 bytes
HTML transferred: 12463429 bytes
Requests per second: 1.42 [#/sec] (mean)
Time per request: 7053.553 [ms] (mean)
Time per request: 705.355 [ms] (mean, across all concurrent requests)
Transfer rate: 172.76 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.1 0 0
Processing: 2666 6838 1842.3 6547 13812
Waiting: 2650 6822 1842.5 6533 13798
Total: 2666 6838 1842.3 6547 13812
Percentage of the requests served within a certain time (ms)
50% 6547
66% 7243
75% 7676
80% 8149
90% 8995
95% 10025
98% 13689
99% 13812
100% 13812 (longest request)
meta-searching이 조회에 포함되는 경우 성능에 현저한 차이가 있음을 확인할 수 있습니다. 첫 번째 실행은 평균적으로 0.5초에 완료된 총 1000개의 요청(10개 동시)이 있는 검색 콜렉션에 대한 것입니다. 두 번째 실행은 평균적으로 6.5초에 완료된 총 100개의 요청(10개 동시)이 있는 콜렉션 및 연합 소스에 대한 것입니다. 연합을 사용하도록 설정한 후에 10번째 요청의 완료 시간은 13배 더 늘어났습니다.
댓글을 달아 주세요