Configure Apache's virtual site

Source: Internet
Author: User
Tags browser cache

About the virtual site of Apache is also heard for a long time, but I am relatively lazy, delayed configuration, but yesterday to do the project encountered a very embarrassing problem,

Let me have to configure ...

First, the reason for the configuration:

Because you want to put the local project on the server. My local directory structure is: D:\phpStudy\www\admin

Admin inside is my laravel project. After the upload through git, found that the Css,js file can not load resources. A closer look, it turns out that because

Local relative to the server, the file directory more admin, so the two are not unified, or the server shows normal, local bashing street. Either local

Normal, server bashing street, so I decided to configure a virtual site, the project directly put up, the simulation server directory results on OK.

(1) Css,js The problem of resources that cannot be loaded on the server:

1, open F12, look at the error message, is the path or the prompt return is not text/css, but text/html

2, if the path is wrong, then adjust the path, if the problem of loading, in the introduction of the time added type= "Text/css"

3, Css,js Sometimes there is a browser cache problem, so you can clear the browsing data to try

Second, the configuration process:

(1) Create new Folder Web under D:\phpStudy, represent our new site file, the path is: D:\phpStudy\web

(2) The second is to enter the hosts under the C disk file, edit our new host name:

At the end of the file, add a piece of code: 127.0.0.1 www.lijinfeng.com (LZ Win7, directory structure as above)

(3) into the Apache configuration file httpd-conf: ctrl+f for Search

1, search: Include conf/extra/httpd-vhosts.conf remove the previous comment, this means to start the virtual machine

(4) Enter Apache configuration file, find: Apache\conf\extra\httpd-vhosts file, edit virtual site configuration:

This is my local virtual site configuration: Garbled because of the Chinese annotation

1, first of all, see I use the 80 port, documentroot corresponding to your file directory, some people may be curious, obviously my

The site is D:\phpStydy\web, why here is a lot of public, this is because of the laravel framework, in order to achieve the input domain name directly access Laravel public/index.php, so this writing.

2, ServerName: This corresponds to your host name: Fill in your host name.

3, DirectoryIndex: This represents your default access page, is generally index.html and index.php

4, the following is the error log, but also the rights control, I did not add, because no use, permission control please see

Here: http://blog.csdn.net/the_victory/article/details/51006167, this blogger writes well.

(5) Restart Apache, browser input: www.lijinfeng.com, you will find that you can visit the site happily.

Iii. Other issues:

(1) Common error: 403 ACCESCC forbidden.

The solution to this problem: 1, check the configuration, ensure servername is not wrong

2, Apache remember to reboot after each change

3, plus permissions this piece, I did not add (ps:apache2.2 and apache2.4 writing is not the same

Be careful)

4, looking for a Niang.

(2) After the configuration was successful, localhost was found unable to access:

Solution: Then build a localhost virtual site, must have localhost, otherwise configure this virtual host Also

It's no fun.

1, the new configuration in the Apache httpd-vhosts:

2, open the Apache configuration file, remove servername localhost this line, and restart

3, into the C disk of the Hosts file, add: 127.0.0.1 localhost

4, visit your localhost, you will find that your localhost is back again

Iv. Other

1, the virtual site can be built a few, here just to build a, do an example

2, there are virtual directory can be configured, this network a lot of, I will not be long-winded here

3, more and more found not a lot of things much better, a little side

With the June.


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.