【问题标题】:Forbidden: You don't have permission to access / on this server, WAMP Error禁止:您无权访问此服务器上的 /,WAMP 错误
【发布时间】:2013-10-23 00:52:15
【问题描述】:

我已经在 windows 8 上安装了 wamp,并且每当我访问 localhost 或 phpmyadmin 时都会收到上述错误。经过大量搜索,我找到了许多答案,包括将 httpd.conf 修改为 Allow from All 等。This 链接显示了这样一个常见的答案以及更多信息。

我的问题是,许多人认为它允许所有用户访问 phpMyAdmin,它不安全且易受攻击等。我想创建完全安全的 WAMP 服务器,如果我这样做可以吗?

有人可以提供一些参考或信息吗?

【问题讨论】:

标签: apache windows-8 phpmyadmin wamp wampserver


【解决方案1】:

1.

首先 TCP 和 UDP 数据包必须允许端口 80(或您使用的任何端口)和 443。为此,请在 Windows 防火墙上为端口 80 和 443 为 TPC 和 UDP 创建 2 个入站规则。 (或者如果允许入站规则,您可以禁用整个防火墙进行测试,但永久解决方案)

2.

如果您使用的是 WAMPServer 3,请参阅答案底部

对于 WAMPServer 版本

您需要更改 Apache 上的安全设置以允许从其他任何地方进行访问,因此请编辑您的 httpd.conf 文件。

将此部分更改为:

#   onlineoffline tag - don't remove
     Order Deny,Allow
     Deny from all
     Allow from 127.0.0.1
     Allow from ::1
     Allow from localhost

收件人:

#   onlineoffline tag - don't remove
    Order Allow,Deny
      Allow from all

如果“全部允许”行不适合您,请使用“要求全部授予” 那么它会为你工作。

WAMPServer 3 有不同的方法

在 WAMPServer 的第 3 版和 > 中,为 localhost 预定义了一个虚拟主机,因此根本不要修改 httpd.conf 文件,保持原样。

使用菜单编辑httpd-vhosts.conf 文件。

应该是这样的:

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot D:/wamp/www
    <Directory  "D:/wamp/www/">
        Options +Indexes +FollowSymLinks +MultiViews
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>

修改为

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot D:/wamp/www
    <Directory  "D:/wamp/www/">
        Options +Indexes +FollowSymLinks +MultiViews
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

注意:如果您在端口 80 以外运行 wamp,则 VirtualHost 将类似于 VirtualHost *:86。(86 或您使用的任何端口)而不是 VirtualHost *:80

3. 进行此更改后不要忘记重新启动 Wamp 或 Apache 的所有服务

【讨论】:

  • 这应该被选为正确答案。 @Hassan 你救了我的命!
  • 很高兴知道它对其他人也有帮助,我将所有研究和方法混合到一个答案中,这样可以节省其他人搜索的时间
  • 在找到这个可行的解决方案之前搜索了很长时间。已确认适用于 3.1。谢谢@HassanSaeed!
  • 很高兴有人解释了WAMP 3。 SO 上的所有其他答案对于此版本均无效。
【解决方案2】:

我发现最好的(也是最不令人沮丧的)路径是从 Allow from All 开始,然后,当您知道它会以这种方式工作时,将其缩小到更安全的 Allow from 127.0.0.1Allow from ::1 (localhost)。

只要您的防火墙配置正确,Allow from all 应该不会引起任何问题,但如果您不需要其他计算机能够访问您的站点,最好只允许来自 localhost。

当您对 httpd.conf 进行更改时,不要忘记重新启动 Apache。它们将在下次启动之前生效。

希望这足以让您入门,网上有很多可用的文档。

【讨论】:

  • 非常感谢,这个非常清晰、及时、描述性强。
  • 确实如此。感谢您的简单回答,对我们这些知之甚少的人没有傲慢的态度。
  • 感谢您提供此解决方案,新安装 WAMP 2.5 时遇到问题。博客链接是解决我的问题的关键。
  • 对于任何在我之后查看此内容的人,上面链接的博客文章不再存在,但这里有一个不同服务器上的链接:hieule.info/web/…
【解决方案3】:

默认情况下,wamp 将以下内容设置为任何未明确声明的目录的默认值:

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

对我来说,如果我注释掉Require all denied 的行,我就可以开始访问相关目录了。我不推荐这个。

我在目录指令中包含Require local,如下所示:

<Directory "C:/GitHub/head_count/">
    AllowOverride All
    Allow from all
    Require local
</Directory>

注意:当我只有Allow from all 时,我的权限仍然被拒绝。添加Require local 对我有帮助。

【讨论】:

  • 这个对我也有用 - 也许 apache 自去年 OP 以来已经发生了变化。关键是需要本地
【解决方案4】:

添加Allow from All 对我不起作用。然后我尝试了这个,它成功了。

操作系统:Windows 8.1
Wamp:2.5

我在文件 C:\wamp\bin\apache\apache2.4.9\conf\extra\httpd-vhosts.conf 中添加了这个

<VirtualHost *:80>
    ServerAdmin localhost@localhost.com
    DocumentRoot "c:/wamp/www/"
    ServerName localhost
    ServerAlias localhost
    ErrorLog "logs/localhost-error.log"
    CustomLog "logs/localhost-access.log" common
</VirtualHost>

【讨论】:

【解决方案5】:

这可能是一种解决方案。

public class RegisterActivity extends AppCompatActivity {

    private static final String TAG = "RegisterActivity";
    private static final String URL_FOR_REGISTRATION = "http://192.168.10.4/android_login_example/register.php";
    ProgressDialog progressDialog;

    private EditText signupInputName, signupInputEmail, signupInputPassword, signupInputAge;
    private Button btnSignUp;
    private Button btnLinkLogin;
    private RadioGroup genderRadioGroup;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        // Progress dialog
        progressDialog = new ProgressDialog(this);
        progressDialog.setCancelable(false);

        signupInputName = (EditText) findViewById(R.id.signup_input_name);
        signupInputEmail = (EditText) findViewById(R.id.signup_input_email);
        signupInputPassword = (EditText) findViewById(R.id.signup_input_password);
        signupInputAge = (EditText) findViewById(R.id.signup_input_age);

        btnSignUp = (Button) findViewById(R.id.btn_signup);
        btnLinkLogin = (Button) findViewById(R.id.btn_link_login);

        genderRadioGroup = (RadioGroup) findViewById(R.id.gender_radio_group);
        btnSignUp.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                submitForm();
            }
        });
        btnLinkLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent i = new Intent(getApplicationContext(),MainActivity.class);
                startActivity(i);
            }
        });
    }

    private void submitForm() {

        int selectedId = genderRadioGroup.getCheckedRadioButtonId();
        String gender;
        if(selectedId == R.id.female_radio_btn)
            gender = "Female";
        else
            gender = "Male";

        registerUser(signupInputName.getText().toString(),
                signupInputEmail.getText().toString(),
                signupInputPassword.getText().toString(),
                gender,
                signupInputAge.getText().toString());
    }

    private void registerUser(final String name,  final String email, final String password,
                              final String gender, final String dob) {
        // Tag used to cancel the request
        String cancel_req_tag = "register";

        progressDialog.setMessage("Adding you ...");
        showDialog();

        StringRequest strReq = new StringRequest(Request.Method.POST,
                URL_FOR_REGISTRATION, new Response.Listener<String>() {

            @Override
            public void onResponse(String response) {
                Log.d(TAG, "Register Response: " + response.toString());
                hideDialog();

                try {
                    JSONObject jObj = new JSONObject(response);
                    boolean error = jObj.getBoolean("error");

                    if (!error) {
                        String user = jObj.getJSONObject("user").getString("name");
                        Toast.makeText(getApplicationContext(), "Hi " + user +", You are successfully Added!", Toast.LENGTH_SHORT).show();

                        // Launch login activity
                        Intent intent = new Intent(
                                RegisterActivity.this,
                                MainActivity.class);
                        startActivity(intent);
                        finish();
                    } else {



                        String errorMsg = jObj.getString("error_msg");
                        Toast.makeText(getApplicationContext(),
                                errorMsg, Toast.LENGTH_LONG).show();
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }
        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                Log.e(TAG, "Registration Error: " + error.getMessage());
                Toast.makeText(getApplicationContext(),
                        error.getMessage(), Toast.LENGTH_LONG).show();
                hideDialog();
            }
        }) {
            @Override
            protected Map<String, String> getParams() {
                // Posting params to register url
                Map<String, String> params = new HashMap<String, String>();
                params.put("name", name);
                params.put("email", email);
                params.put("password", password);
                params.put("gender", gender);
                params.put("age", dob);
                return params;
            }
        };
        // Adding request to request queue
        AppSingleton.getInstance(getApplicationContext()).addToRequestQueue(strReq, cancel_req_tag);
    }

    private void showDialog() {
        if (!progressDialog.isShowing())
            progressDialog.show();
    }

    private void hideDialog() {
        if (progressDialog.isShowing())
            progressDialog.dismiss();
    }
    }

【讨论】:

  • 请告诉我值不会保存在本地主机上,谢谢
猜你喜欢
  • 2012-09-12
  • 2012-01-12
  • 2012-05-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多