我在我的CentOs 7 Apache服务器中使用以下httpd.conf配置来运行“site1”:
ServerRoot "/etc/httpd"
Listen 80
Include conf.modules.d/*.conf
User apache
Group apache
ServerAdmin root@localhost
ServerName locahost:80
<Directory />
AllowOverride none
Require all denied
</Directory>
DocumentRoot "/var/www/html/site1"
<Directory "/var/www">
AllowOverride None
# Allow open access:
Require all granted
</Directory>
<Directory "/var/www/html/site1">
Options FollowSymLinks
AllowOverride all
Order allow,deny
Allow from all
</Directory>
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
<Files ".ht*">
Require all denied
</Files>
ErrorLog "logs/error_log"
LogLevel warn
<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
<IfModule logio_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
CustomLog "logs/access_log" combined
</IfModule>
<IfModule alias_module>
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
</IfModule>
<Directory "/var/www/cgi-bin">
AllowOverride None
Options None
Require all granted
</Directory>
<IfModule mime_module>
TypesConfig /etc/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
</IfModule>
AddDefaultCharset UTF-8
<IfModule mime_magic_module>
MIMEMagicFile conf/magic
</IfModule>
EnableSendfile on
IncludeOptional conf.d/*.conf
当我访问“http://localhost”时,site1及其子页面/子文件夹正常工作。我现在想要能够显示第二个网站:当访问“http://localhost/site2”时,我想显示保存在“/ test”下的文件“test.html”的内容;我应该如何编辑httpd.conf以使其工作?
这不是一个不同的网站,它是一个不同的目录。不同的站点将涉及不同的主机名。
由于您已经拥有DocumentRoot "/var/www/html/site1
并且您似乎不想创建新的虚拟主机,因此您可以使用Alias
指向新的/不同的目录
另外你只想让site2在/ test /下加载test.html如果我在访问时理解正确,只需添加正确的DirectoryIndex
指令即可。
这里是:
Alias /site2 /var/www/html/site2
<Directory /var/www/html/site2>
DirectoryIndex /test/test.html
</Directory>
为此,您需要以下两个模块:
您也可以在site1下使用mkdir site2,但这可能看起来更干净。