Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache 如何自定义具有IP地址的URL_Apache_Url_Ip Address_Httpd.conf - Fatal编程技术网

Apache 如何自定义具有IP地址的URL

Apache 如何自定义具有IP地址的URL,apache,url,ip-address,httpd.conf,Apache,Url,Ip Address,Httpd.conf,是否可以配置上面有我的IP地址的URL,如:“”。这种情况是当我在PC上运行Apache服务器,并在其中加载localhost时。我知道在使用外部服务器托管之后,这是可能的,但是我们有没有办法在本地主机中进行配置 如何配置Apache文件来实现这一点?我尝试在我的本地主机中编辑“httpd.conf”,通过像这样在内部添加它-请告诉我问题出在哪里 ServerName localhost:80 HostnameLookups Off <VirtualHost *:80>

是否可以配置上面有我的IP地址的URL,如:“”。这种情况是当我在PC上运行Apache服务器,并在其中加载localhost时。我知道在使用外部服务器托管之后,这是可能的,但是我们有没有办法在本地主机中进行配置

如何配置Apache文件来实现这一点?我尝试在我的本地主机中编辑“httpd.conf”,通过像这样在内部添加它-请告诉我问题出在哪里

ServerName localhost:80  
HostnameLookups Off  
<VirtualHost *:80>
   # This first-listed virtual host is also the default for *:80  
ServerName www.example.com  
ServerAlias example.com  
DocumentRoot /www/domain  
</VirtualHost>  

<VirtualHost *:80>  
ServerName other.example.com  
DocumentRoot /www/otherdomain  
</VirtualHost>  
DocumentRoot "c:/wamp/www/"                 
ServerName本地主机:80
主机名查询
#第一个列出的虚拟主机也是*:80的默认主机
服务器名www.example.com
ServerAlias example.com
DocumentRoot/www/domain
ServerName other.example.com
DocumentRoot/www/otherdomain
DocumentRoot“c:/wamp/www/”

是的,您可以在计算机上使用多个IP地址。配置取决于您的操作系统。这篇文章是针对linux的

但是,更好的方法是基于主机名或(最简单的)端口使用VirtualHost。在第一种情况下,第二种情况下

下面是来自的Apache服务器配置示例

#确保Apache侦听端口80
听80
#侦听所有IP地址上的虚拟主机请求
名称虚拟主机*:80
DocumentRoot/www/example1
服务器名www.example.com
#这里还有其他指示
DocumentRoot/www/example2
服务器名www.example.org
#这里还有其他指示

您有一个从互联网上看不到的专用IP。为了从您的本地网络外部访问您的本地服务器,路由器应该将请求转发到端口80上的外部接口,再转发到您的本地IP上的服务器。使用(第2步或第3步只是广告,请仔细查看继续链接)。仅供参考-如果您询问的是本地网络中仅域名的DNS服务器,或正常的域和端口转发,或手动修改您想要访问服务器的每台计算机上的
主机
文件。谢谢@Alex Dvoretsky-现在,这很有趣。。。请帮助我如何使用虚拟主机。Iam使用Windows PC。例如,使用Apache Web服务器很简单。我在回答中加了一个例子。但是我不确定要编辑哪个文件,是不是“httpd.conf”是的,它是
httpd.conf
还有一个问题:在我的WAMP文件夹中,我可以找到一个名为“httpd-vhosts.conf”的文件&我可以在那里看到上面的内容。这就是要修改的文件!!
# Ensure that Apache listens on port 80
Listen 80

# Listen for virtual host requests on all IP addresses
NameVirtualHost *: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>