Configuration of Apache VirtualHost

Source: Internet
Author: User
Tags php development environment

Since the computer was replaced by Mac, there has been no time to configure the PHP environment. Cause every time you want to change the PHP code, is a local change, and then push directly to the server to run such development and testing and its time-consuming and cumbersome, so in the morning specifically decided to fix the PHP development environment under the Mac, after all, Ax, once in a while.

After download follow the good mamp, select Web Server for Apache. Change the configuration file httpd.conf, add the appropriate load Moudle. Open the virtual configuration. Httpd-vhost.conf, because the current project has two separate projects, namely the front.xxx.local.admin.xxx.local

The httpd-vhost.conf configuration is as follows:

# # Virtual hosts## If you want to maintain multiple domains/hostnames on your# machine can setup VirtualHost containers forthem. Most configurations# use only name-based virtual hosts so the server doesn't need to worry about# IP addresses. This was indicated by the asterisksinchThe Directives below.## the documentation at #<url:http://httpd.apache.org/docs/2.2/vhosts/># forfurther details before you try-to-Setup virtual hosts.## the command line option'- S'To verify your virtual host# configuration.## use name-based virtual hosting.# #NameVirtualHost*: the# # VirtualHost example:# almost any Apache directive could go into a VirtualHost container.# the first VirtualHost secti on is used forAll requests that Donot# match a ServerName or ServeraliasinchAny <VirtualHost>block.#<virtualhost *: the>DocumentRoot"/users/fly_popc/desktop/code/front/web"ServerName front.xxx.local Serveralias front.xxx.local<directory"/users/fly_popc/desktop/code/front/web">Rewriteengine on Rewritecond%{request_filename}!-F Rewritecond%{request_filename}!-d rewriterule. index.php</directory></virtualhost><virtualhost *: the>DocumentRoot"/users/fly_popc/desktop/code/admin/web"ServerName admin.xxx.local Serveralias admin.xxx.local<directory"/users/fly_popc/desktop/code/admin/web">Rewriteengine on Rewritecond%{request_filename}!-F Rewritecond%{request_filename}!-d rewriterule. index.php</Directory></VirtualHost>

After restarting Apache, the environment is functioning normally.

But...

When the background project is accessed, it is routed to the first address, that is, Apache configures multiple domain names to point to the virtual host access always point to the first virtual host. After several posts have been queried, the problem is still not resolved. Finally realize that there is a configuration is not open, that is:

# #use name-* :

Based on the spirit of the trace, the following query the meaning of the configuration, the reasons are as follows:

Namevirtualhost If you don't have this,<virtualhost> tag, it doesn't work. Based on the situation of domain name access, if the IP access based on the first designated IP VirtualHost, each IP can be specified separately) a namevirtualhost can be used for multiple <virtualhost>, each < Virtualhost> must have its own namevirtualhostnamevirutalhost *:80 to make this host IP and port, if there is more than one IP on the server, you can make a certain IP port is which host. (The new version of Apache has removed the namevirtualhost configuration because it does not work, and the parameters are already indicated in the VirtualHost).

Now open the browser, respectively access http://front.xxx.local and http://admin.xxx.local can each access to the corresponding page, done! The entire process is documented below.

1. First, in the httpd.conf (this is the general Apache configuration file), the virtual path comments are removed.
#Include etc/extra/httpd-vhosts.conf
It is possible to make the httpd-vhosts.conf file work, or to write the configuration directly in httpd.conf, but this is not recommended.
The related configurations are: Listen namevirtualhost <VirtualHost>

2.Listen to listen to the port, multiple ports, to write multiple listen, otherwise Apache boot, will not start the corresponding socket.

Like what

8080

3.NameVirtualHost without this,<virtualhost> tag would have no effect.

4. The most critical virtualhost.
Important: When Apache receives a request, it first defaults to the first virtualhost, then matches it, and if there is no match, the first VirtualHost works.
So in httpd.conf, the <dicrectory/> (this is the default configuration for all directories)
And <Direcotry/opt/lampp/htdocs> permissions, all are deny from all. As the default, or directly in the httpd.conf configuration

<directory/>    Options Indexes followsymlinks     </Directory>

At this point, the project will be able to run properly!

Configuration of Apache VirtualHost

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.