【问题标题】:virtual host Redirects Me To Apache default Page Testing 123虚拟主机将我重定向到 Apache 默认页面测试 123
【发布时间】:2021-06-05 07:25:18
【问题描述】:

我在我的服务器中设置了任何东西以连接到域但我有一个问题 Httpd 虚拟主机将我重定向到默认 Apache 页面我不知道为什么我尝试了 Internet 上的所有解决方案但没有任何效果。 这是我的文件,如果需要任何其他信息,请告诉我:

<VirtualHost *:80>
    documentRoot /var/www/buymeacookie.ir/public_html
    ServerName buymeacookie.ir
    ErrorLog /var/www/buymeacookie.ir/error.log
    CustomLog /var/www/buymeacookie.ir/requests.log combined
    #Redirect "/" "https://www.buymeacookie.ir/"
</VirtualHost>

我也做了 /var/www/buymeacookie.ir/

和/var/www/buymeacookie.ir/public_html/

并在 public_html 上添加了 index.html 但是当我打开我的 URL 时,我得到了 Apache 的默认页面。

感谢您的阅读:D

EDIT /var/www 的树是

/var/www
├── buymeacookie.ir
│   ├── access.log
│   ├── error_log
│   ├── error.log
│   ├── public_html
│   │   └── index.html
│   └── requests.log
├── cgi-bin
└── html

【问题讨论】:

  • 1 index.html 文件的内容是什么? 2 您的配置文件中是否还有另一个 VirtualHost?将使用它找到的第一个(从上到下)。 3/var/www/buymeacookie.ir/public_html 添加一个&lt;Directory&gt; 部分以设置此目录的权限。 4 添加LogLevel Debug 并重启。看看你的日志。 5 查看你对目录的权限。
  • @Nic3500 index.html 的内容很简单&lt;html&gt; &lt;head&gt; &lt;title&gt;Welcome to Example.com!&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;h1&gt;Success! The example.com virtual host is working!&lt;/h1&gt; &lt;/body&gt; &lt;/html&gt; 2 据我所知没有其他虚拟主机 3 我添加了&lt;Directory&gt; 4 我应该在哪里添加LogLevelDebug 5 它们都是777 权限
  • @Nic3500 启用日志级别警告并收到此错误[autoindex:error] [pid 2748] [client 5.74.12.148:4628] AH01276: Cannot serve directory /var/www/html/buymeacookie.ir/public_html/: No matching DirectoryIndex (index.php,index.html) found, and server-generated directory index forbidden by Options directive
  • 所以在你的 VirtualHost 中添加一个DirectoryIndex 指令来指定默认服务的文件。
  • 仍然得到相同的错误配置文件` ServerName buymeacookie.ir ServerAlias www.buymeacookie.ir ServerAdmin root@buymeacookie.ir DocumentRoot /var/www/buymeacookie.ir/public_html DirectoryIndex index .html 选项索引 FollowSymLinks MultiViews AllowOverride All 要求所有已授予 loglevel warn ErrorLog /var/www/buymeacookie.ir/error.log CustomLog /var/www/ buymeacookie.ir/access.log 结合 '

标签: apache redirect virtualhost httpd.conf


【解决方案1】:

.conf 文件的第 2 行错误:必须是 DocumentRoot,而不是 documentRoot

【讨论】:

  • 对不起,不是这样。我只是在我自己的Apache上试过,即使大小写不准确也没关系。
【解决方案2】:

这就是我配置这样一个站点的方式。我从您的问题中得出的要求:

  • 域:www.example.com 和 example.com
  • 此域的文件位于 /var/www/example.com/public_html/
  • 该域设置为 VirtualHost,该域具有单独的日志
  • 重要提示:80 端口没有其他虚拟主机
  • Apache 的顶级目录将是 /opt/apache
  • 日志将在 /opt/apache/logs 中结束
  • 默认内容文件位于 /opt/apache/htdocs
  • /var/www/example.com/public_html/ 必须归用户 httpd、组 httpd、权限 750 所有
  • 如果由其他用户拥有,则权限应为 755,但这不太安全
  • 必须根据您的要求添加或删除模块
  • 显然,您必须根据您的系统调整目录

/opt/apache/conf/httpd.conf

ServerRoot "/opt/apache"

Listen 80

LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authn_core_module modules/mod_authn_core.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule authz_core_module modules/mod_authz_core.so
LoadModule access_compat_module modules/mod_access_compat.so
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule reqtimeout_module modules/mod_reqtimeout.so
LoadModule filter_module modules/mod_filter.so
LoadModule mime_module modules/mod_mime.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule env_module modules/mod_env.so
LoadModule headers_module modules/mod_headers.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule version_module modules/mod_version.so
LoadModule slotmem_shm_module modules/mod_slotmem_shm.so
LoadModule unixd_module modules/mod_unixd.so
LoadModule status_module modules/mod_status.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule dir_module modules/mod_dir.so

<IfModule unixd_module>
    User httpd
    Group httpd
</IfModule>

ServerName example.com:80

<Directory />
    AllowOverride none
    Require all denied
</Directory>

DocumentRoot "/opt/apache/htdocs"
<Directory "/opt/apache/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>

ErrorLog "logs/error_log"
LogLevel debug
<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 mime_module>
    TypesConfig conf/mime.types

    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
</IfModule>

Include conf/extra/httpd-mpm.conf
Include conf/extra/httpd-vhosts.conf
Include conf/extra/httpd-default.conf

/opt/apache/conf/extra/httpd-vhosts.conf

<VirtualHost *:80>

    ServerName example.com
    ServerAlias www.example.com

    ServerAdmin misc@example.com

    LogLevel debug
    ErrorLog "logs/example.com_error_log"
    CustomLog "logs/example.com_access_log" combined

    DocumentRoot "/var/www/example.com/public_html/"
    <Directory "/var/www/example.com/public_html/">
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
    </Directory>

    DirectoryIndex index.html

</VirtualHost>

使用此设置:

  • 如果您调用http://www.example.comhttp://example.com,文件将来自/var/www/example.com/public_html/
  • /opt/apache/logs 下的日志将指示 httpd 的开始
  • logs /opt/apache/logs/example.com_*_log 将显示您的测试中的事务和/或错误

显然,这是一个起点,您必须根据其他要求进行调整。

【讨论】:

  • 我的 opt 文件夹中只有 rh
  • 我在这里展示的示例不一定与您系统上的完全相同。根据您的发行版,Apache httpd 安装在不同的目录中。因此,当您在发行版上安装 httpd 时,请查看软件包以了解文件所在系统的位置。
猜你喜欢
  • 1970-01-01
  • 2017-06-04
  • 2011-07-22
  • 2010-10-06
  • 2016-03-26
  • 2016-07-16
  • 2016-04-29
  • 2020-02-16
  • 2023-03-27
相关资源
最近更新 更多