【问题标题】:Apache wrong localhost locationApache错误的本地主机位置
【发布时间】:2015-03-01 16:49:00
【问题描述】:

经过多次尝试并收到 403 Forbidden 错误:

http://localhost/

Forbidden
You don't have permission to access / on this server.
Apache/2.4.7 (Ubuntu) Server at localhost Port 80

我终于查了apachectl -S,发现本地主机文件夹的位置设置不正确:

$ apachectl -S

Main DocumentRoot: "/var/www"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex default: dir="/var/lock/apache2" mechanism=fcntl 
Mutex mpm-accept: using_defaults
Mutex watchdog-callback: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33 not_used
Group: name="www-data" id=33 not_used

它清楚地表明我的 localhost 文件夹是 /var/www 而我的设置是别的东西:

/etc/apache2/sites-available/mynewsite.conf

<VirtualHost *:80>

    ServerAdmin webmaster@localhost
    DocumentRoot /home/user/www

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

/etc/apache2/apache2.conf

Mutex file:${APACHE_LOCK_DIR} default
PidFile ${APACHE_PID_FILE}
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
HostnameLookups Off
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf
Include ports.conf

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Require all denied
</Directory>

<Directory /usr/share>
    AllowOverride None
    Require all granted
</Directory>

<Directory /home/user/www>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

AccessFileName .htaccess
<FilesMatch "^\.ht">
    Require all denied
</FilesMatch>
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
IncludeOptional conf-enabled/*.conf
IncludeOptional sites-enabled/*.conf
ServerName localhost

对于文件权限:

$ ls -la /home/user/

total 3097944
drwx------  9 user user          4096 Jan  3 19:28 .
drwxr-xr-x 45 user user          4096 Jan  3 20:46 ..
drwxr-xr-x 48 user www-data       4096 Jan  3 20:30 www

Apache重启也没问题:

$ sudo service apache2 restart
 * Restarting web server apache2                                         [ OK ] 

我想知道怎么了?

【问题讨论】:

  • 你试过chmod a+x /home/user吗?如果无法访问/home/user/,我认为www-data 将无法访问/home/user/www/
  • 非常感谢。那是确切的问题。现在解决了。但是有什么方法可以在User: name="www-data" id=33 not_used 中显示user,所以不需要更改权限?
  • 不客气,我已经发表了我的评论作为答案(请接受)。我不确定你的新问题到底是什么意思,继续为那个问题打开一个新的 Stackoverflow 问题!

标签: apache ubuntu permissions localhost http-status-code-403


【解决方案1】:

您必须执行chmod a+x /home/user/,因为如果无法访问/home/user/,www-data 将无法访问/home/user/www/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-29
    • 1970-01-01
    • 2018-06-26
    • 1970-01-01
    • 2013-07-12
    • 2011-05-13
    • 1970-01-01
    相关资源
    最近更新 更多