apache - Apache 不能在 localhost 以外的网站上运行
问题描述
VirtualHost 文件仅适用于 localhost 用户,而不适用于任何 ip,无论是公共的、私有的还是自己的。这是放在sites-enabled
文件夹中的 VirtualHost 文件内容:
<VirtualHost *:80>
ServerName localhost
ServerAdmin root@localhost
DocumentRoot /home/matecat/cattool
DirectoryIndex index.php index.php3 index.html index.htm index.shtml
<Directory /home/matecat/cattool/>
Options All
AllowOverride All
<IfVersion < 2.4>
Order allow,deny
Allow from all
</IfVersion>
<IfVersion >= 2.4>
Require all granted
</IfVersion>
ExpiresActive On
ExpiresByType text/html "access plus 1 hour"
ExpiresByType text/css "access plus 1 week"
ExpiresByType text/javascript "access plus 1 week"
ExpiresByType image/gif "access plus 1 week"
ExpiresByType image/jpeg "access plus 1 week"
ExpiresByType image/jpg "access plus 1 week"
ExpiresByType image/png "access plus 1 week"
ExpiresByType image/vnd.microsoft.icon "access plus 1 week"
ExpiresByType image/ico "access plus 1 week"
ExpiresByType application/x-shockwave-flash "access plus 1 week"
</Directory>
php_flag register_globals off
php_flag magic_quotes_gpc off
php_admin_flag short_open_tag on
php_value memory_limit 1024M
php_value upload_max_filesize 200M
php_value post_max_size 200M
LogLevel error
ErrorLog /var/log/apache2/matecat.error.log
CustomLog /var/log/apache2/matecat.log combined
ServerSignature Off
# Configuration for Nodejs proxy
ProxyRequests off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location /sse/ >
ProxyPass http://0.0.0.0:7788/
ProxyPassReverse http://0.0.0.0:7788/
</Location>
</VirtualHost>
我注释掉了以下几行:
Servername localhost
ServerAdmin root@localhost
但是在重新启动apache服务器后,使用系统的“IPv4”仍然无法正常工作。
解决方案
如果您没有指定域,并通过 IP 访问它,Apache 将使用它找到的第一个匹配的 VirtualHost,自上而下。
这里,任何 IP (*),端口 80。所以如果默认配置 VirtualHost 没有被注释掉,Apache 将使用这个默认配置。所以注释掉默认的,或者把你的移到默认的。但是无论如何都没有人需要该默认配置:-)
推荐阅读
- javascript - 如何从 JSON 对象返回特定数量的单词?
- angular - 将 Angular 10 与 BsDatepickerConfig 和 ngModel 一起使用 - 存储日期,而不是时间
- xaml - Uno Platform - 共享项目中的参考资源字典
- angular - 为什么 LoadingController 在 API 调用期间尝试将其关闭时会抛出“覆盖不存在”
- lua - 是否可以在不使用 loadstring 的情况下从字符串加载脚本
- javascript - 如何使用按钮进行倒计时输入
- scala - getquill / protoquill 查询执行出错
- google-sheets - 在使用 sumifs 时,我如何为特定标准提供多个选项
- flutter - 如何在颤动中将图像网址转换为资产?
- typescript - 使用对象的值创建类型