Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/23.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/6/apache/9.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
Linux 如何在Centos 7上设置网站目录(自定义主机)_Linux_Apache_Dns_Virtualhost - Fatal编程技术网

Linux 如何在Centos 7上设置网站目录(自定义主机)

Linux 如何在Centos 7上设置网站目录(自定义主机),linux,apache,dns,virtualhost,Linux,Apache,Dns,Virtualhost,在我将DNS指向服务器之后,我正试图弄清楚如何使网站发挥作用 默认情况下,在新安装apache、mysql、php之后,主服务器目录位于var/www/html,因此如果我上传测试html文件,通过默认服务器ip,html文件将显示出来 我正在尝试设置一个自定义文件夹,即var/www/examplewebsite.com/public_html,然后public_html将作为用户访问我的网站时的“转到”文件夹。一台IP服务器上有多个网站也很好 我从中找到了一些信息,但我没有看到名称Virtu

在我将DNS指向服务器之后,我正试图弄清楚如何使网站发挥作用

默认情况下,在新安装apache、mysql、php之后,主服务器目录位于var/www/html,因此如果我上传测试html文件,通过默认服务器ip,html文件将显示出来

我正在尝试设置一个自定义文件夹,即var/www/examplewebsite.com/public_html,然后public_html将作为用户访问我的网站时的“转到”文件夹。一台IP服务器上有多个网站也很好

我从中找到了一些信息,但我没有看到名称VirtualHost及其下面的段落


我是Centos/Linux环境的新手,如有任何帮助,将不胜感激:

这里有一个很好的教程:

基本上,为测试目的创建文件夹和索引:

sudo vi /var/www/example.com/public_html/index.html
在apache配置文件中添加虚拟指令:

NameVirtualHost *:80
#
# NOTE: NameVirtualHost cannot be used without a port specifier
# (e.g. :80) if mod_ssl is being used, due to the nature of the
# SSL protocol.
#    

#    
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
# 
<VirtualHost *:80>
     ServerAdmin webmaster@example.com
     DocumentRoot /var/www/example.com/public_html
     ServerName www.example.com
     ServerAlias example.com
     ErrorLog /var/www/example.com/error.log
     CustomLog /var/www/example.com/requests.log
</VirtualHost>

检查Centos 7的此文档。他们有一个很好的初始教程

首先,我建议您检查是否安装了httpd服务并处于活动状态

sudo service httpd status
如果不活动 一旦激活 检查端口80和443 https是否处于活动状态

sudo netstat -tulnap | grep :80
sudo netstat -tulnap | grep :443
如果它们处于活动状态,请测试服务器。或 默认情况下,它应该转到apache Web服务器页面

一旦你能看到这一页。尝试在中创建初始index.html页面 /var/www/html

vi/var/www.html/index.html 单击i以插入 复制以下html 测验 测试网页

在本教程中,他们将解释其余的配置

@该教程为读者提供了一个很好的长材料,我得到了版主的正确答案。我认为该网站足够长,足以澄清这个问题,我认为再次复制教程在这里不是正确的答案

还要查看下一个文档,了解Apache2.2和2.4之间的更改


如果您有任何问题,请在此处进行评论

这对CentOS 7不起作用。Apache版本已从2.2更改为2.4。NameVirtualHost指令不再有效。
sudo service httpd start
sudo netstat -tulnap | grep :80
sudo netstat -tulnap | grep :443