547

Apacheを自分で構成し、仮想ホストにphpMyAdminを読み込もうとしましたが、次のように受け取りました。

403Forbiddenこのサーバーにアクセスする/アクセスする権限がありません

私のhttpd.conf

#
# This is the main Apache HTTP server configuration file.  It contains the
# configuration directives that give the server its instructions.
# See <URL:http://httpd.apache.org/docs/2.2> for detailed information.
# In particular, see 
# <URL:http://httpd.apache.org/docs/2.2/mod/directives.html>
# for a discussion of each configuration directive.
#
# Do NOT simply read the instructions in here without understanding
# what they do.  They're here only as hints or reminders.  If you are unsure
# consult the online docs. You have been warned.  
#
# Configuration and logfile names: If the filenames you specify for many
# of the server's control files begin with "/" (or "drive:/" for Win32), the
# server will use that explicit path.  If the filenames do *not* begin
# with "/", the value of ServerRoot is prepended -- so "logs/foo.log"
# with ServerRoot set to "C:/Program Files (x86)/Apache Software Foundation/Apache2.2" will be interpreted by the
# server as "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/logs/foo.log".
#
# NOTE: Where filenames are specified, you must use forward slashes
# instead of backslashes (e.g., "c:/apache" instead of "c:\apache").
# If a drive letter is omitted, the drive on which httpd.exe is located
# will be used by default.  It is recommended that you always supply
# an explicit drive letter in absolute paths to avoid confusion.

#
# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.
#
# Do not add a slash at the end of the directory path.  If you point
# ServerRoot at a non-local disk, be sure to point the LockFile directive
# at a local disk.  If you wish to share the same ServerRoot for multiple
# httpd daemons, you will need to change at least LockFile and PidFile.
#
ServerRoot "C:/Program Files (x86)/Apache Software Foundation/Apache2.2"

#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to 
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
Listen 127.0.0.1:80

Include conf/vhosts.conf

#
# Dynamic Shared Object (DSO) Support
#
# To be able to use the functionality of a module which was built as a DSO you
# have to place corresponding `LoadModule' lines at this location so the
# directives contained in it are actually available _before_ they are used.
# Statically compiled modules (those listed by `httpd -l') do not need
# to be loaded here.
#
# Example:
# LoadModule foo_module modules/mod_foo.so
#
LoadModule actions_module modules/mod_actions.so
LoadModule alias_module modules/mod_alias.so
LoadModule asis_module modules/mod_asis.so
LoadModule auth_basic_module modules/mod_auth_basic.so
#LoadModule auth_digest_module modules/mod_auth_digest.so
#LoadModule authn_alias_module modules/mod_authn_alias.so
#LoadModule authn_anon_module modules/mod_authn_anon.so
#LoadModule authn_dbd_module modules/mod_authn_dbd.so
#LoadModule authn_dbm_module modules/mod_authn_dbm.so
LoadModule authn_default_module modules/mod_authn_default.so
LoadModule authn_file_module modules/mod_authn_file.so
#LoadModule authnz_ldap_module modules/mod_authnz_ldap.so
#LoadModule authz_dbm_module modules/mod_authz_dbm.so
LoadModule authz_default_module modules/mod_authz_default.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_host_module modules/mod_authz_host.so
#LoadModule authz_owner_module modules/mod_authz_owner.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule autoindex_module modules/mod_autoindex.so
#LoadModule cache_module modules/mod_cache.so
#LoadModule cern_meta_module modules/mod_cern_meta.so
LoadModule cgi_module modules/mod_cgi.so
#LoadModule charset_lite_module modules/mod_charset_lite.so
#LoadModule dav_module modules/mod_dav.so
#LoadModule dav_fs_module modules/mod_dav_fs.so
#LoadModule dav_lock_module modules/mod_dav_lock.so
#LoadModule dbd_module modules/mod_dbd.so
#LoadModule deflate_module modules/mod_deflate.so
LoadModule dir_module modules/mod_dir.so
#LoadModule disk_cache_module modules/mod_disk_cache.so
#LoadModule dumpio_module modules/mod_dumpio.so
LoadModule env_module modules/mod_env.so
#LoadModule expires_module modules/mod_expires.so
#LoadModule ext_filter_module modules/mod_ext_filter.so
#LoadModule file_cache_module modules/mod_file_cache.so
#LoadModule filter_module modules/mod_filter.so
#LoadModule headers_module modules/mod_headers.so
#LoadModule ident_module modules/mod_ident.so
#LoadModule imagemap_module modules/mod_imagemap.so
LoadModule include_module modules/mod_include.so
#LoadModule info_module modules/mod_info.so
LoadModule isapi_module modules/mod_isapi.so
#LoadModule ldap_module modules/mod_ldap.so
#LoadModule logio_module modules/mod_logio.so
LoadModule log_config_module modules/mod_log_config.so
#LoadModule log_forensic_module modules/mod_log_forensic.so
#LoadModule mem_cache_module modules/mod_mem_cache.so
LoadModule mime_module modules/mod_mime.so
#LoadModule mime_magic_module modules/mod_mime_magic.so
LoadModule negotiation_module modules/mod_negotiation.so
#LoadModule proxy_module modules/mod_proxy.so
#LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
#LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
#LoadModule proxy_connect_module modules/mod_proxy_connect.so
#LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
#LoadModule proxy_http_module modules/mod_proxy_http.so
#LoadModule proxy_scgi_module modules/mod_proxy_scgi.so
#LoadModule reqtimeout_module modules/mod_reqtimeout.so
#LoadModule rewrite_module modules/mod_rewrite.so
LoadModule setenvif_module modules/mod_setenvif.so
#LoadModule speling_module modules/mod_speling.so
#LoadModule ssl_module modules/mod_ssl.so
#LoadModule status_module modules/mod_status.so
#LoadModule substitute_module modules/mod_substitute.so
#LoadModule unique_id_module modules/mod_unique_id.so
#LoadModule userdir_module modules/mod_userdir.so
#LoadModule usertrack_module modules/mod_usertrack.so
#LoadModule version_module modules/mod_version.so
#LoadModule vhost_alias_module modules/mod_vhost_alias.so
LoadModule php5_module "c:/Program Files/php/php5apache2_2.dll" 

<IfModule !mpm_netware_module>
<IfModule !mpm_winnt_module>
#
# If you wish httpd to run as a different user or group, you must run
# httpd as root initially and it will switch.  
#
# User/Group: The name (or #number) of the user/group to run httpd as.
# It is usually good practice to create a dedicated user and group for
# running httpd, as with most system services.
#
User daemon
Group daemon

</IfModule>
</IfModule>

# 'Main' server configuration
#
# The directives in this section set up the values used by the 'main'
# server, which responds to any requests that aren't handled by a
# <VirtualHost> definition.  These values also provide defaults for
# any <VirtualHost> containers you may define later in the file.
#
# All of these directives may appear inside <VirtualHost> containers,
# in which case these default settings will be overridden for the
# virtual host being defined.
#

#
# ServerAdmin: Your address, where problems with the server should be
# e-mailed.  This address appears on some server-generated pages, such
# as error documents.  e.g. admin@your-domain.com
#
ServerAdmin webmaster@somenet.com

#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
#ServerName www.somenet.com:80

#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs"

#
# Each directory to which Apache has access can be configured with respect
# to which services and features are allowed and/or disabled in that
# directory (and its subdirectories). 
#
# First, we configure the "default" to be a very restrictive set of 
# features.  
#
<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
</Directory>

#
# Note that from this point forward you must specifically allow
# particular features to be enabled - so if something's not working as
# you might expect, make sure that you have specifically enabled it
# below.
#

#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.2/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride None

    #
    # Controls who can get stuff from this server.
    #
    Order allow,deny
    Allow from all

</Directory>

#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>

#
# The following lines prevent .htaccess and .htpasswd files from being 
# viewed by Web clients. 
#
<FilesMatch "^\.ht">
    Order allow,deny
    Deny from all
    Satisfy All
</FilesMatch>

#
# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
# container, error messages relating to that virtual host will be
# logged here.  If you *do* define an error logfile for a <VirtualHost>
# container, that host's errors will be logged there and not here.
#
ErrorLog "logs/error.log"

#
# LogLevel: Control the number of messages logged to the error_log.
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
#
LogLevel warn

<IfModule log_config_module>
    #
    # The following directives define some format nicknames for use with
    # a CustomLog directive (see below).
    #
    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>
      # You need to enable mod_logio.c to use %I and %O
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>

    #
    # The location and format of the access logfile (Common Logfile Format).
    # If you do not define any access logfiles within a <VirtualHost>
    # container, they will be logged here.  Contrariwise, if you *do*
    # define per-<VirtualHost> access logfiles, transactions will be
    # logged therein and *not* in this file.
    #
    CustomLog "logs/access.log" common

    #
    # If you prefer a logfile with access, agent, and referer information
    # (Combined Logfile Format) you can use the following directive.
    #
    #CustomLog "logs/access.log" combined
</IfModule>

<IfModule alias_module>
    #
    # Redirect: Allows you to tell clients about documents that used to 
    # exist in your server's namespace, but do not anymore. The client 
    # will make a new request for the document at its new location.
    # Example:
    # Redirect permanent /foo http://www.somenet.com/bar

    #
    # Alias: Maps web paths into filesystem paths and is used to
    # access content that does not live under the DocumentRoot.
    # Example:
    # Alias /webpath /full/filesystem/path
    #
    # If you include a trailing / on /webpath then the server will
    # require it to be present in the URL.  You will also likely
    # need to provide a <Directory> section to allow access to
    # the filesystem path.

    #
    # ScriptAlias: This controls which directories contain server scripts. 
    # ScriptAliases are essentially the same as Aliases, except that
    # documents in the target directory are treated as applications and
    # run by the server when requested rather than as documents sent to the
    # client.  The same rules about trailing "/" apply to ScriptAlias
    # directives as to Alias.
    #
    ScriptAlias /cgi-bin/ "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/cgi-bin/"

</IfModule>

<IfModule cgid_module>
    #
    # ScriptSock: On threaded servers, designate the path to the UNIX
    # socket used to communicate with the CGI daemon of mod_cgid.
    #
    #Scriptsock logs/cgisock
</IfModule>

#
# "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/cgi-bin" should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
#
<Directory "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/cgi-bin">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
</Directory>

#
# DefaultType: the default MIME type the server will use for a document
# if it cannot otherwise determine one, such as from filename extensions.
# If your server contains mostly text or HTML documents, "text/plain" is
# a good value.  If most of your content is binary, such as applications
# or images, you may want to use "application/octet-stream" instead to
# keep browsers from trying to display binary files as though they are
# text.
#
DefaultType text/plain

<IfModule mime_module>
    #
    # TypesConfig points to the file containing the list of mappings from
    # filename extension to MIME-type.
    #
    TypesConfig conf/mime.types

    #
    # AddType allows you to add to or override the MIME configuration
    # file specified in TypesConfig for specific file types.
    #
    #AddType application/x-gzip .tgz
    #
    # AddEncoding allows you to have certain browsers uncompress
    # information on the fly. Note: Not all browsers support this.
    #
    #AddEncoding x-compress .Z
    #AddEncoding x-gzip .gz .tgz
    #
    # If the AddEncoding directives above are commented-out, then you
    # probably should define those extensions to indicate media types:
    #
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz

    #
    # AddHandler allows you to map certain file extensions to "handlers":
    # actions unrelated to filetype. These can be either built into the server
    # or added with the Action directive (see below)
    #
    # To use CGI scripts outside of ScriptAliased directories:
    # (You will also need to add "ExecCGI" to the "Options" directive.)
    #
    #AddHandler cgi-script .cgi

    # For type maps (negotiated resources):
    #AddHandler type-map var

    #
    # Filters allow you to process content before it is sent to the client.
    #
    # To parse .shtml files for server-side includes (SSI):
    # (You will also need to add "Includes" to the "Options" directive.)
    #
    #AddType text/html .shtml
    #AddOutputFilter INCLUDES .shtml

    AddType application/x-httpd-php .php 
</IfModule>

#
# The mod_mime_magic module allows the server to use various hints from the
# contents of the file itself to determine its type.  The MIMEMagicFile
# directive tells the module where the hint definitions are located.
#
#MIMEMagicFile conf/magic

#
# Customizable error responses come in three flavors:
# 1) plain text 2) local redirects 3) external redirects
#
# Some examples:
#ErrorDocument 500 "The server made a boo boo."
#ErrorDocument 404 /missing.html
#ErrorDocument 404 "/cgi-bin/missing_handler.pl"
#ErrorDocument 402 http://www.somenet.com/subscription_info.html
#

#
# MaxRanges: Maximum number of Ranges in a request before
# returning the entire resource, or one of the special
# values 'default', 'none' or 'unlimited'.
# Default setting is to accept 200 Ranges.
#MaxRanges unlimited

#
# EnableMMAP and EnableSendfile: On systems that support it, 
# memory-mapping or the sendfile syscall is used to deliver
# files.  This usually improves server performance, but must
# be turned off when serving from networked-mounted 
# filesystems or if support for these functions is otherwise
# broken on your system.
#
#EnableMMAP off
#EnableSendfile off

# Supplemental configuration
#
# The configuration files in the conf/extra/ directory can be 
# included to add extra features or to modify the default configuration of 
# the server, or you may simply copy their contents here and change as 
# necessary.

# Server-pool management (MPM specific)
#Include conf/extra/httpd-mpm.conf

# Multi-language error messages
#Include conf/extra/httpd-multilang-errordoc.conf

# Fancy directory listings
#Include conf/extra/httpd-autoindex.conf

# Language settings
#Include conf/extra/httpd-languages.conf

# User home directories
#Include conf/extra/httpd-userdir.conf

# Real-time info on requests and configuration
#Include conf/extra/httpd-info.conf

# Virtual hosts
#Include conf/extra/httpd-vhosts.conf

# Local access to the Apache HTTP Server Manual
#Include conf/extra/httpd-manual.conf

# Distributed authoring and versioning (WebDAV)
#Include conf/extra/httpd-dav.conf

# Various default settings
#Include conf/extra/httpd-default.conf

# Secure (SSL/TLS) connections
#Include conf/extra/httpd-ssl.conf
#
# Note: The following must must be present to support
#       starting without SSL on platforms with no /dev/random equivalent
#       but a statically compiled-in mod_ssl.
#
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>

PHPIniDir "c:/Program Files/php" 

およびvhosts.conf:

NameVirtualHost 127.0.0.1:80

<VirtualHost 127.0.0.1:80>
    DocumentRoot i:/projects/webserver/__tools/phpmyadmin/
    ServerName dbadmin.tools
</VirtualHost>
4

34 に答える 34

687

2016年10月更新

4年前、この回答は多くの人に参考にされており、セキュリティの観点から多くのことを学びましたが、重要な注意事項を明確にする責任があると感じ、それに応じて回答を更新しました。

元の答えは正しいですが、一部の実稼働環境では安全ではありません。さらに、環境のセットアップ中に発生する可能性のあるいくつかの問題について説明したいと思います。

迅速な解決策を探していて、セキュリティが重要ではない場合、つまり開発環境の場合は、スキップして元の回答を読んでください。

多くのシナリオは403Forbiddenにつながる可能性があります:


A.ディレクトリインデックス(からmod_autoindex.c

ディレクトリにアクセスし、このディレクトリにデフォルトのファイルが見つから ず、 Apacheがこのディレクトリに対してOptions Indexes有効になっていない場合。

A.1。DirectoryIndexオプションの例

DirectoryIndex index.html default.php welcome.php

A.2。Options Indexesオプション

設定されている場合、デフォルトのファイルが見つからない場合、apacheはディレクトリの内容を一覧表示します(上記のオプションから)

上記の条件のいずれも満たされない場合

403Forbiddenを受け取ります

推奨事項

  • 本当に必要な場合を除いて、ディレクトリリストを許可しないでください。
  • デフォルトのインデックスDirectoryIndexを最小に制限します。
  • 変更する場合は、変更を必要なディレクトリのみに制限します。たとえば、.htaccessファイルを使用するか、変更を<Directory /my/directory>ディレクティブ内に配置します。

B.deny,allowディレクティブ(Apache 2.2)

コメントで@Radu、@ Simon A. Eugsterが言及しました。 リクエストは、これらのディレクティブによって拒否、ブラックリスト、またはホワイトリストに登録されています。

完全な説明は投稿しませんが、いくつかの例が理解に役立つと思います。つまり、このルールを覚えておいてください。

両方が一致した場合、最後のディレクティブが勝ちます

Order allow,deny

両方のディレクティブが一致した場合、拒否が勝ちます(ディレクティブがconfのallow後に記述されている場合でも)deny

Order deny,allow

両方のディレクティブが一致した場合、allowが勝ちます

例1

Order allow,deny
Allow from localhost mydomain.com

localhostと*.mydomain.comのみがこれにアクセスでき、他のすべてのホストは拒否されます

例2

Order allow,deny
Deny from evil.com
Allow from safe.evil.com # <-- has no effect since this will be evaluated first

すべてのリクエストが拒否され、最後の行があなたを騙す可能性がありますが、最後の勝利ルール(ここでは拒否が最後です)の両方に一致する場合は、次のように書かれていることを覚えておいてください。

Order allow,deny
Allow from safe.evil.com
Deny from evil.com # <-- will override the previous one 

例4

Order deny,allow
Allow from site.com
Deny from untrusted.site.com # <-- has no effect since this will be matched by the above `Allow` directive

すべてのホストからのリクエストを受け付けます

例4:一般的な公開サイト(ブラックリストに載っていない限り許可)

Order allow,deny
Allow from all
Deny from hacker1.com
Deny from hacker2.com

例5:イントラネットおよびセキュアサイトで一般的(ホワイトリストに登録されていない限り拒否)

Order deny,allow
Deny from all
Allow from mypc.localdomain
Allow from managment.localdomain

C.Requireディレクティブ(Apache 2.4)

Apache 2.4は、という新しいモジュールを使用しますmod_authz_host

Require all granted=>すべてのリクエストを許可する

Require all denied=>すべてのリクエストを拒否する

Require host safe.com=>safe.comからのみ許可されます


D.ファイルのアクセス許可

ほとんどの人が間違っていることの1つは、ファイルのアクセス許可を構成することです。

黄金律は

許可なしで開始し、必要に応じて追加します

Linuxの場合:

  • ディレクトリにはExecute許可が必要です

  • ファイルにはRead権限が必要です

  • はい、あなたは正しいExecuteですファイルの権限を追加しないでください

たとえば、このスクリプトを使用してフォルダーのアクセス許可を設定します

# setting permissions for /var/www/mysite.com

# read permission ONLY for the owner 
chmod -R /var/www/mysite.com 400 

# add execute for folders only
find /var/www/mysite.com -type d -exec chmod -R u+x {} \;

# allow file uploads 
chmod -R /var/www/mysite.com/public/uploads u+w

# allow log writing to this folder
chmod -R /var/www/mysite.com/logs/ 

このコードを例として投稿しましたが、他の状況ではセットアップが異なる場合があります



元の回答

同じ問題に直面しましたが、 httpd.confのグローバルディレクトリ設定またはhttpd-vhosts.confの特定のディレクトリブロックのいずれかでoptionsディレクティブを設定することで解決しました。

Options Indexes FollowSymLinks Includes ExecCGI

デフォルトでは、グローバルディレクトリ設定は(httpd.conf line ~188)次のとおりです。

<Directory />
    Options FollowSymLinks
    AllowOverride All
    Order deny,allow
    Allow from all
</Directory>

オプションを次のように設定します。 Options Indexes FollowSymLinks Includes ExecCGI

最後に、次のようになります。

<Directory />
    #Options FollowSymLinks
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Order deny,allow
    Allow from all
</Directory>

また、行を変更Order deny,allowしてAllow from allみてくださいRequire all granted

付録

ディレクトリインデックスのソースコード(簡潔にするために一部のコードは削除されています)

if (allow_opts & OPT_INDEXES) {
     return index_directory(r, d);
} else {
        const char *index_names = apr_table_get(r->notes, "dir-index-names");

        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01276)
                      "Cannot serve directory %s: No matching DirectoryIndex (%s) found, and "
                      "server-generated directory index forbidden by "
                      "Options directive",
                       r->filename,
                       index_names ? index_names : "none");
        return HTTP_FORBIDDEN;
    }
于 2012-07-02T07:19:26.807 に答える
193

この問題が解決されたことは理解していますが、たまたま同じ問題を自分で解決しました。

の原因

禁止このサーバーにアクセスする権限がありません

は、実際にはのapacheディレクトリのデフォルト設定ですhttpd.conf

#
# Each directory to which Apache has access can be configured with respect
# to which services and features are allowed and/or disabled in that
# directory (and its subdirectories). 
#
# First, we configure the "default" to be a very restrictive set of 
# features.  
#
<Directory "/">
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all          # the cause of permission denied
</Directory>

に変更Deny from allするだけAllow from allで、権限の問題が解決するはずです。

あるいは、より良いアプローチは、仮想ホスト構成で個々のディレクトリ権限を指定することです。

<VirtualHost *:80>
    ....

    # Set access permission
    <Directory "/path/to/docroot">
        Allow from all
    </Directory>

    ....
</VirtualHost>

ただし、Apache-2.4以降、アクセス制御は新しいモジュールを使用して行われますmod_authz_host2.2から2.4へのアップグレード)。したがって、新しいRequireディレクティブを使用する必要があります。

<VirtualHost *:80>
    ....

    # Set access permission
    <Directory "/path/to/docroot">
        Require all granted
    </Directory>

    ....
</VirtualHost>
于 2013-02-03T10:59:48.993 に答える
137

デフォルトの/var/ www /の外部でホストされているディレクトリの一般的な落とし穴は、Apacheユーザーがサイトがホストされているディレクトリとサブディレクトリへのアクセス許可を必要としないことです。Apacheには、サイトがホストされているファイルシステムのルートまでのすべてのディレクトリへのアクセス許可が必要です。Apacheは、インストール時に/ var / www /に割り当てられたアクセス許可を自動的に取得するため、ホストディレクトリがその真下にある場合、これは適用されません。編集:Daybreakerは、彼のApacheがデフォルトディレクトリへの正しいアクセス許可なしでインストールされたことを報告しました。

たとえば、開発マシンがあり、サイトのディレクトリは次のとおりです。

/username/home/Dropbox/myamazingsite/

あなたはあなたが逃げることができると思うかもしれません:

chgrp -R www-data /username/home/Dropbox/myamazingsite/
chmod -R 2750 /username/home/Dropbox/myamazingsite/

これにより、Apacheにサイトのディレクトリにアクセスする権限が与えられるからですか?それは正しいですが、それだけでは十分ではありません。Apacheにはディレクトリツリーのずっと上までアクセス許可が必要なので、実行する必要があるのは次のとおりです。

chgrp -R www-data /username/
chmod -R 2750 /username/

明らかに、本番サーバー上のApacheへのアクセスを、そのディレクトリ構造の内容を分析せずに完全なディレクトリ構造に許可することはお勧めしません。本番環境では、デフォルトのディレクトリまたはWebアセットを保持するためだけの別のディレクトリ構造を維持するのが最善です。

Edit2:u / chimerahaが指摘したように、アクセス許可で何をしているのかわからない場合は、サイトのディレクトリをホームディレクトリから移動して、ホームディレクトリからロックアウトされる可能性を回避することをお勧めします。

于 2013-01-31T10:28:54.487 に答える
66

一部の構成パラメーターは、Apache2.4で変更されました。Zend Framework 2アプリケーションをセットアップしているときに、同様の問題が発生しました。いくつかの調査の後、ここに解決策があります:

正しくない構成

<VirtualHost *:80>
    ServerName zf2-tutorial.localhost
    DocumentRoot /path/to/zf2-tutorial/public
    SetEnv APPLICATION_ENV "development"
    <Directory /path/to/zf2-tutorial/public>
        DirectoryIndex index.php
        AllowOverride All
        Order allow,deny #<-- 2.2 config
        Allow from all #<-- 2.2 config
    </Directory>
</VirtualHost>

正しい構成

<VirtualHost *:80>
    ServerName zf2-tutorial.localhost
    DocumentRoot /path/to/zf2-tutorial/public
    SetEnv APPLICATION_ENV "development"
    <Directory /path/to/zf2-tutorial/public>
        DirectoryIndex index.php
        AllowOverride All
        Require all granted #<-- 2.4 New configuration
    </Directory>
</VirtualHost>

Apache 2.2から2.4への移行を計画している場合は、次の参考資料を参照してください:http: //httpd.apache.org/docs/2.4/upgrading.html

于 2014-07-10T00:09:53.527 に答える
45

Apache2.2を使用

Order Deny,Allow
Allow from all

Apache2.4を使用

Require all granted

http://httpd.apache.org/docs/2.4/en/upgrading.htmlから

于 2015-06-05T15:06:38.903 に答える
24

Apache2.4を使用するUbuntu14.04、私は次のことを行いました。

次のファイルをapache2.conf(の下/etc/apache2)に追加します。

<Directory /home/rocky/code/documentroot/>
  Options Indexes FollowSymLinks
  AllowOverride None
  Require all granted
</Directory>

サーバーをリロードします。

sudo service apache2 reload

編集:これは、Apache2.4を搭載したOSXYosemiteでも機能します。最も重要な行は

付与されたすべてを要求する

于 2014-07-21T19:35:34.127 に答える
22

WAMPサーバーを使用している場合は、次のことを試してください。

  • タスクバーのWAMPサーバーアイコンをシングルクリックします

  • オンラインにするオプションを選択します

  • サーバーは自動的に再起動します

  • 次に、ローカルWebサイトにアクセスしてみてください

于 2013-02-27T06:53:03.730 に答える
21

SELinuxでCentOSを使用している場合は、次を試してください。

sudo restorecon -r /var/www/html

詳細:https ://www.centos.org/forums/viewtopic.php?t = 6834#p31548

于 2014-11-26T17:06:21.610 に答える
17

ユーザーをに追加することで問題を解決しましたhttpd.conf

# User/Group: The name (or #number) of the user/group to run httpd as.
# It is usually good practice to create a dedicated user and group for
# running httpd, as with most system services.
#
#User daemon
User my_username
Group daemon
于 2012-12-28T20:52:40.103 に答える
14

この記事「Apache2.2で仮想ホストを作成する」は、最上位の仮想ホストディレクトリへのアクセス許可(ポイント9)に役立ちます。

この行をvhosts.confファイルに追加するだけです。

<Directory I:/projects/webserver>
    Order Deny,Allow
    Allow from all
</Directory>
于 2012-06-04T13:47:00.903 に答える
11

私は同じエラーを受け取り、何年もの間問題を理解することができませんでした。CentOSなどのSELinuxを含むLinuxディストリビューションを使用している場合は、ドキュメントのルートファイルに対してSELinuxのアクセス許可が正しく設定されていることを確認する必要があります。そうしないと、このエラーが発生します。これは、標準のファイルシステムのアクセス許可とはまったく異なるアクセス許可のセットです。

たまたまチュートリアルApacheとSELinuxを使用しましたが、何を探すべきかがわかれば、周りにはたくさんあるようです。

于 2012-12-18T01:58:49.413 に答える
6

MAMP Proを使用している場合、これを修正する方法は、 [ - ]タブ Indexesの下のチェックボックスをオンにすることです。HostsExtended

MAMP Pro v3.0.3では、次のようになります。 ここに画像の説明を入力してください

于 2014-10-06T14:51:04.053 に答える
5

この問題を解決する別の方法があります。に存在するディレクトリ「subphp」/var/www/html/subphpにアクセスし、を使用してアクセスする127.0.0.1/subphpと、次のようなエラーが発生したとします。

このサーバーの/subphp/にアクセスする権限がありません。

次に、ディレクトリのアクセス許可を「なし」から「ファイルへのアクセス」に変更します。コマンドラインユーザーは、chmodコマンドを使用して権限を変更できます。

于 2012-12-02T11:59:02.470 に答える
3

同じ問題が発生しましたが、apacheのパスをvar / wwwの外部のフォルダーに変更したため、問題が発生し始めました。

var / www / html> home / dev / projectにシンボリックリンクを作成して修正しました。これは、権限を変更することなく、トリックを実行しているようです...

于 2014-07-31T21:29:33.143 に答える
3

私はMacOSXを使用していますが、私の場合、apacheでphpを有効にするのを忘れています。必要なのは、次の1行のコメントを解除することだけです/etc/apache2/httpd.conf

LoadModule php5_module libexec/apache2/libphp5.so

詳細については、この記事を参照してください。

于 2016-08-19T01:22:24.420 に答える
2

(WindowsおよびApache 2.2.xの場合)

「禁止」エラーは、仮想ホストが定義されていないことの結果でもあります。

Julienが指摘したように、virtualを使用する場合はhosts.conf、httpdファイルに移動し、次の行のコメントを解除します。

#Include conf/extra/httpd-vhosts.conf

次に、仮想ホスト定義をに追加し、conf/extra/httpd-vhosts.confApacheを再起動します。

于 2014-06-05T16:39:06.263 に答える
2

私はこの問題に遭遇しました、そして私の解決策はwww-dataが適切なフォルダーを所有していなかったということでした、そして代わりに私はそれをユーザーの1人が所有するように設定しました。(私は少し凝ったことをしようとしていましたが、ftpをうまく再生させるための誤ったトリックです。)

実行後:

chown -R www-data:www-data /var/www/html

マシンはデータの提供を再開しました。を使用して、現在フォルダを所有しているユーザーを確認できます。

ls -l /var/www/html
于 2015-05-11T15:59:24.720 に答える
2

このソリューションはすべてから許可されていません

パブリックディレクトリwwwを変更して、PCとWifiで接続されたモバイルからアクセスしたいだけです。私はUbuntu16.04を持っています。

  1. そのため、最初に/etc/apache2/sites-enabled/000-default.conf を変更し、新しいパブリックディレクトリDocumentRoot "/ media / data / XAMPP/htdocs"のDocumentRoot/var / www/html行を変更しました。

  2. 次に、/ etc / apache2 / apache2.confを変更し、ローカルホストとモバイルのアクセス許可を設定しました。今回はIPアドレスを使用しましたが、完全に安全ではないことはわかっていますが、私の目的には問題ありません。

    <Directory/>
        Options FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from localhost 10.42.0.11
    </Directory>
    
于 2017-01-25T16:04:15.990 に答える
1

これを試して、何も追加しないでくださいOrder allow,deny

AddHandler cgi-script .cgi .py 
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
    AllowOverride None
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Require all granted
    Allow from all
</Directory>

 

sudo a2enmod cgi
sudo service apache2 restart
于 2015-04-28T09:54:36.667 に答える
1
    I changed 
    Order Deny,Allow
    Deny From All      in .htaccess to   " Require all denied "    and restarted apache but it did not help.

ubuntuのapache2.confのパスは/etc/apache2/apache.confです

次に、apache2.confに次の行を追加すると、フォルダーが正常に機能します

    <Directory /path of required folder>
            Options Indexes FollowSymLinks
            AllowOverride All
            Require all granted
       </Directory>

   and run  " Sudo service apache2 restart " 
于 2017-10-14T03:54:15.740 に答える
1

この質問にはすでにいくつかの答えがあることを私は知っていますが、言及されているものの、前の答えでは十分に強調されていない非常に微妙な側面があると思います。

Apacheの構成またはファイルのアクセス許可を確認する前に、アクセスするファイル(ドキュメントのルートにあるindex.phpファイルなど)へのフルパスを構成するディレクトリが読み取り可能ですが、Webサーバーユーザーが実行することもできます。

たとえば、ドキュメントルートへのパスが「/ var / www/html」であるとします。すべての「var」、「www」、および「html」ディレクトリがWebサーバーユーザーによって(読み取り可能で)実行可能であることを確認する必要があります。私の場合(Ubuntu 16.04)、誤って「html」ディレクトリから「others」グループの「x」フラグを削除したため、アクセス許可は次のようになりました。

drwxr-xr-- 15 root root 4096 Jun 11 16:40 html

ご覧のとおり、Webサーバーユーザー(この場合は「others」権限が適用されます)には「html」ディレクトリへの実行アクセス権がなく、これが問題の根本原因でした。発行後:

chmod o+x html

コマンド、問題が修正されました!

この方法を解決する前に、私はこのスレッドで文字通り他のすべての提案を試しましたが、提案はほとんど偶然に見つけたコメントに埋もれていたので、ここで強調して拡張することが役立つと思います。

于 2018-07-16T17:34:25.830 に答える
0

私は特定のコントローラーについてのみ同じ問題を抱えていました-それは本当に奇妙でした。CIフォルダーのルートに、アクセスしようとしたコントローラーと同じ名前のフォルダーがありました...そのため、CIは、コントローラー自体ではなく、このディレクトリーに要求を送信していました。

このフォルダを削除した後(少し間違ってありました)、すべて正常に機能しました。

より明確にするために、これはそれがどのように見えたかです:

/ci/controller/register.php

/ci/register/

削除する必要がありました/ci/register/

于 2013-03-21T05:28:34.057 に答える
0

ファイルを配置する場所を正確に確認し、Documentsフォルダーにネストしないでください。

たとえば、前述のようにドキュメントフォルダにコードを配置するのを間違えました。ドキュメントは明示的にあなただけが利用でき、APACHEは利用できないため、これは機能しません。1つのディレクトリに移動してみてください。この問題が発生しない場合があります。

次の場所からフォルダを移動します。

/ Users / YOURUSERNAME / Documents / code

ここへ:/ Users / YOURUSERNAME / code

于 2013-08-05T15:54:00.833 に答える
0

私もこの問題に走ったときに別の貢献をもたらすために:

望まないVirtualHostを構成しました。仮想ホストのインクルードが発生した行をコメントアウトしましたが、機能しました。

于 2013-09-18T14:46:43.503 に答える
0

設定ファイルを変更した後は、忘れずにRestart All Services

私はそれに3時間の時間を無駄にしました。

于 2014-07-18T00:56:39.167 に答える
0

youralias.conf次のコードのようにファイルを変更できます。

Alias /Quiz/ "h:/MyServer/Quiz/" 
 <Directory "h:/MyServer/Quiz/">
   Options Indexes FollowSymLinks
   AllowOverride all
   <IfDefine APACHE24>
     Require local
   </IfDefine>
   <IfDefine !APACHE24>
    Order Deny,Allow
    Deny from all
    Allow from localhost ::1 127.0.0.1
   </IfDefine>
 </Directory>
于 2015-06-25T18:06:56.467 に答える
0

この状況で構成する正しいファイルは、phpMyAdminエイリアスのhttpd.confではなく、にあることに注意してくださいbin/apache/your_version/conf/httpd.conf

次の行を探します。

DocumentRoot "c:/wamp/www/"

#
# Each directory to which Apache has access can be configured with respect
# to which services and features are allowed and/or disabled in that
# directory (and its subdirectories).
#
# First, we configure the "default" to be a very restrictive set of
# features.
#
<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Allow from all
</Directory>

に設定されていることを確認してくださいAllow from all...

そうでない場合、phpMyAdminは機能する可能性がありますが、ルートやその下の他のフォルダーは機能しません。また、WAMPを再起動してからオンラインにすることを忘れないでください...

これは私の頭痛を解決しました。

于 2015-11-15T05:59:14.897 に答える
0

Dockerビルドを実行する前に、 SSHFSを使用してローカルファイルシステムからVirtualBoxゲストにファイルをマウントすると、この問題が発生しました。結局のところ、「修正」は、SSHFSマウント内からビルドするのではなく、すべてのファイルをVirtualBoxインスタンスにコピーし、そこからビルドを実行することでした。

于 2016-06-08T18:17:22.323 に答える
0

作業方法(他に問題がない場合)

デフォルトでは、ApacheはIPv4(共通の外部IPアドレス)からのアクセスを制限していません

制限されているのは、' httpd.conf'で指定されたコマンドです。

すべて交換してください

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

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

したがって、 Apacheに与えられたすべての制限を削除します。

C:/ wamp /www/ディレクトリRequire localRequire all grantedに置き換えます。

<Directory "c:/wamp/www/">
    Options Indexes FollowSymLinks
    AllowOverride all
    Require all granted
    # Require local
</Directory>
于 2016-06-25T17:39:37.803 に答える
0

これはかなりばかげていますが、ダウンロードしようとしたファイルがファイルシステムにない場合、403Forbiddenを取得しました。この場合、apacheエラーはあまり正確ではなく、ファイルを本来あるべき場所に置いただけですべてが機能しました。

于 2016-07-22T20:47:44.213 に答える
0

modsecを有効にし、サイトのエラーログでmodsec IDを確認してから、ファイルの場所の一致をvhost(または.htaccessだと思います)に入力します。

 <LocationMatch "/yourlocation/index.php">
    <IfModule security2_module>
        SecRuleRemoveById XXXXXXX
    </IfModule>
</LocationMatch>
于 2016-11-10T09:55:42.590 に答える
0

この増え続けるリストに別の潜在的な落とし穴を追加するために、私の問題(CentOS 6.8を実行)は、別のサーバーで正常に動作する特定の仮想ホストにありました。問題は、mod_rewriteを使用した.htaccessファイルの障害であることが判明しました。

.htaccessでは、これにより403エラーが発生しました。 <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / </IfModule>

最初の行として FollowSymLinksを追加すると、問題が修正されました。 <IfModule mod_rewrite.c> Options +FollowSymLinks RewriteEngine On RewriteBase / </IfModule>

于 2017-04-03T20:32:48.387 に答える
0

権限エラー

私のような非常に初心者のユーザーの中には、ページに誤ったアクセス許可が設定されている場合にこの問題に直面するものがあります(特に、「他の」ユーザーには読み取りアクセス許可がありません)。たとえば、index.htmlにアクセスしようとして、上記のエラーが発生したとします。修正するには、次のように入力します。

chmod o+r index.html

その後、サーバーに再度アップロードします。エラーが消えます。

于 2017-04-07T13:51:19.720 に答える
0

RiggsFollyは、他の場所で私のためにこれに答えました。

Apache confフォルダーの編集ファイル:httpd-vhost.conf

ディレクトリネスト内に次の小さな行を追加します。

Require ip 192.168.1

サーバー、Apache、Wamp、またはお持ちのものを再起動します。

これで、すべてのHOMEデバイス(IP範囲192.168.1.xxx)がPCサーバーを認識できるようになりました。IP番号の最初の3つの部分のみを追加することに注意してください)。

問題があれば、ファイアウォールを終了してテストします。

ネットワークデバイスのIP番号を確認するには、PC用またはAndroid用の「IPスキャナー」ソフトウェア(かなりの数の無料のもの)をダウンロードして、PlayストアからFingを入手してください。

于 2017-04-29T18:36:52.003 に答える