WAMP - 从项目的URL删除本地主机 [英] WAMP - Remove localhost from project URL

查看:1151
本文介绍了WAMP - 从项目的URL删除本地主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在WAMP项目的URL不解决如我期望。例如,我期望在文件夹c项目:\\ WAMP \\ WWW \\ PROJECT1有URL 的http:// PROJECT1 / ,但它实际上具有URL 的http://本地主机/ PROJECT1 /

The URLs of my projects in WAMP are not resolving as I'd expect. For example, I'd expect the project in the folder c:\wamp\www\project1 to have the URL http://project1/, but it actually has the URL http://localhost/project1/.

这可以访问服务器变量时,会出现问题。我该如何解决这个问题?

This can cause problems when accessing server variables. How do I fix this?

推荐答案

其实这种变化是由WAMPServer开发商和一个很好的理由打算。

Actually this change was intend by the WAMPServer developers and for a good reason.

有是使用本地主机/ PROJECT1 URL和默认WAMPServer DocumentRoot的一个问题,它会导致一些框架和话语preSS型环境问题,以及作为自己的code如果您使用的是code依赖于寂寂服务器环境中任何事物。

There is a problem using the localhost/project1 url and the default WAMPServer DocumentRoot in that it causes problems for some frameworks and WordPress type environments, as well as your own code if you are using code which depends on knowing anything about the server environment.

正确的解决办法是为所有的项目甚至包括那些你在 \\ WAMP \\ WWW \\ PROJECT1 风格的文件夹存储创建虚拟主机。

The correct solution is to create Virtual Hosts for all your projects even those that you store in the \wamp\www\project1 style folders.

在这样做的DocumentRoot的是 \\ WAMP \\ WWW ,这是什么原因导致了这些问题。

When doing that the DocumentRoot is \wamp\www and that is what causes these problems.

这些工具预期的DocumentRoot是站点的根目录,即 \\ WAMP \\ WWW \\ PROJECT1 ,这样,当他们使用PHP变量,如

These tools expect the DocumentRoot to be the root of the site i.e. \wamp\www\project1 so that when they use PHP variables like

$_SERVER['HTTP_HOST']
$_SERVER['SERVER_NAME']
$_SERVER['DOCUMENT_ROOT']

他们得到正确的答案,即答案,他们将得到托管只是该网站一个个活生生的服务器上。

they get the correct answer i.e. the answer they would get on a real live server hosting just that site.

因此​​,使用本地主机\\ PROJECT1 风格的URL将意味着这些变量将返回

So using the localhost\project1 style url would mean these variables would return

$_SERVER['HTTP_HOST'] = localhost
$_SERVER['SERVER_NAME'] = localhost
$_SERVER['DOCUMENT_ROOT'] = C:/wamp/www

当他们回来

$_SERVER['HTTP_HOST'] = project1
$_SERVER['SERVER_NAME'] = project1
$_SERVER['DOCUMENT_ROOT'] = C:/wamp/www/project1

所以,你应该怎样做才能让我的项目菜单的工作和减少复制网站服务器住你的痛苦是:

So what you should do to make the My Projects menu work and reduce your pain in copying sites to live servers is:

创建HOSTS文件中像这样每个项目的条目,并记住创建一个通过IPV6 IPV4通过(127.0.0.1)和一个接入访问(:: 1): -

Create an entry in the HOSTS file for each project like so and remember to create one for access via IPV4(127.0.0.1) and one for access via IPV6 (::1):-

127.0.0.1 localhost
127.0.0.1 project1

::1 localhost
::1 project1

记住任何更改这个文件等之后刷新Windows的DNS缓存,以便: -

Remember to refresh the Windows DNS Cache after any change to this file like so :-

使用启动命令窗口以管理员身份运行并运行: -

Start a command window using Run as Administrator and run :-

net stop Dnscache
net start Dnscache

现在,你必须创建一个虚拟主机定义,因此编辑 \\ WAMP \\ BIN \\ apache的\\ apache2.4.9 \\的conf \\额外\\的httpd-vhost.conf 文件( Apache的版本可能不同)

Now you must create a Virtual Host definition, so edit the \wamp\bin\apache\apache2.4.9\conf\extra\httpd-vhost.conf file ( apache versions may differ )

删除默认的东西在里面你第一次做到这一点。然后创建像这样的虚拟主机定义: -

Delete the default stuff in there the first time you do this. And then create your Virtual Host definitions like so :-

#
# Use name-based virtual hosting.
# This next line is not required if you are using Apache 2.4.x and should be deleted
NameVirtualHost *:80

## should be first so the wamp menu page loads and is the default site
## should also never be changed from only allowing access from the local machine
## for a bit of extra security from casual ip address probing
<VirtualHost *:80>
    DocumentRoot "C:/wamp/www"
    ServerName  localhost
    ServerAlias localhost
    <Directory  "C:/wamp/www">
        AllowOverride All

        <IfDefine APACHE24>
            Require local
        </IfDefine>

        <IfDefine !APACHE24>
            Order Deny,Allow
            Deny from all
            Allow from 127.0.0.1 localhost ::1
        </IfDefine>
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/wamp/www/project1"
    ServerName  project1
    ServerAlias project1
    <Directory  "C:/wamp/www/project1">
        AllowOverride All

        <IfDefine APACHE24>
            Require local
        </IfDefine>

        <IfDefine !APACHE24>
            Order Deny,Allow
            Deny from all
            Allow from 127.0.0.1 localhost ::1
        </IfDefine>

    </Directory>
</VirtualHost>

现在,你还需要一个变化,则必须取消注释的httpd.conf 的线,包括我们刚刚改变了上述文件。所以编辑的httpd.conf 文件,使用wampmanager菜单要做到这一点,因为它确保编辑正确的文件。

Now you need one more change, you must uncomment the line in httpd.conf that includes the above file we have just changed. So edit the httpd.conf file, use the wampmanager menus to do this as it ensures you edit the correct file.

找到这一行的#include的conf /额外/的httpd-vhosts.conf 和删除注释从符号该行的开头就像这样: -

Find this line #Include conf/extra/httpd-vhosts.conf and remove the comment # symbol from the beginning of the line like so :-

Include conf/extra/httpd-vhosts.conf

现在你当然会需要重新启动Apache,以便它拿起您的配置更改。

Now of course you will need to restart Apache so that it picks up your configuration changes.

如果Apache不启动,你可能在配置犯了一个错误,要找出什么是错的尝试。

If Apache does not restart, you probably made a mistake in the config, to find out what is wrong try this.

打开命令窗口和 CD \\ WAMP \\ BIN \\ apache的\\ apache2.4.9 \\ BIN 文件夹

Open a command window and CD into the \wamp\bin\apache\apache2.4.9\bin folder.

然后运行这个: -

Then run this :-

httpd -t

如果该错误是在的httpd.conf 的httpd-vhost.conf 文件,它会告诉你错误,也给你的行号,以使查找错误很容易的。

If the error is in httpd.conf or the httpd-vhost.conf files it will tell you the error and also give you the line number to make finding the error very easy.

这篇关于WAMP - 从项目的URL删除本地主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆