草庐IT

php - Nginx 和 PHP-FPM - 权限被拒绝 - Windows

coder 2024-06-11 原文

我正在尝试在 Windows 10 中使用 nginx 配置 PHP 服务器,但我遇到了一些问题。

我想做什么?

如果我访问本地主机,我会看到 phpinfo 页面(确定)
如果我访问 localhost/phpmyadmin,我会看到访问被拒绝。 (失败)
如果我访问 localhost/laravel/public,我会看到 laravel 框架的欢迎页面。

文件夹结构

D:/Server/apps/phpmyadmin (phpmyadmin 应用程序)
D:/服务器/bin/nginx
D:/服务器/bin/php
D:/Server/conf/nginx/nginx.conf
D:/Server/conf/php/php.ini
D:/服务器/日志/nginx
D:/服务器/日志/php
D:/Server/www/index.php (phpinfo页面)
D:/Server/www/laravel(laravel项目)

我试过什么? 我添加 phpmyadmin.app do windows hosts 文件并将另一个服务器 block 添加到 nginx.conf 并工作,但我不想这样做。

错误日志

2015/12/20 14:14:14 [error] 6932#10736: *1 FastCGI sent in stderr: "PHP Warning:  Unknown: failed to open stream: Permission denied in Unknown on line 0" while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "GET /phpmyadmin/ HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "localhost"

主机.access.log

127.0.0.1 - - [20/Dec/2015:14:35:19 -0200] "GET /phpmyadmin/ HTTP/1.1" 403 46 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36" "-"
127.0.0.1 - - [20/Dec/2015:15:59:43 -0200] "GET /phpmyadmin/index.php HTTP/1.1" 404 564 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36" "-"
127.0.0.1 - - [20/Dec/2015:16:01:37 -0200] "GET / HTTP/1.1" 200 24385 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36" "-"
127.0.0.1 - - [20/Dec/2015:16:01:39 -0200] "GET /laravel/public/ HTTP/1.1" 200 402 "http://localhost/laravel/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36" "-"

nginx-start.bat

@echo off
echo Starting Nginx...
D:\Server\bin\hidec D:\Server\bin\nginx\nginx -c D:\Server\conf\nginx\nginx.conf -p D:\Server\bin\nginx
echo Starting PHP FastCGI...
D:\Server\bin\hidec D:\Server\bin\php\php-cgi -b 127.0.0.1:9000 -c D:\Server\conf\php\php.ini

nginx.conf

worker_processes  auto;

error_log  D:/Server/logs/nginx/error.log;

events {
    worker_connections  1024;
    multi_accept        off;
}

http {
    include       D:/Server/bin/nginx/conf/mime.types;
    default_type  application/octet-stream;

    fastcgi_temp_path       D:/Server/tmp/nginx/fastcgi;
    uwsgi_temp_path         D:/Server/tmp/nginx/uwsgi;
    scgi_temp_path          D:/Server/tmp/nginx/scgi;
    client_body_temp_path   D:/Server/tmp/nginx/client-body 1 2;
    proxy_temp_path         D:/Server/tmp/nginx/proxy;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

    server_name_in_redirect off;
    server_tokens           off;

    server_names_hash_bucket_size 64;
    server_names_hash_max_size    512;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    types_hash_max_size 2048;

    client_body_buffer_size     64k;
    client_header_buffer_size   4k;
    client_max_body_size        8M;
    large_client_header_buffers 4 64k;

    client_body_timeout     10;
    client_header_timeout   10;
    keepalive_timeout       30;
    send_timeout            10;
    keepalive_requests      10;

    fastcgi_connect_timeout      60;
    fastcgi_send_timeout         120;
    fastcgi_read_timeout         300;
    fastcgi_buffer_size          64k;
    fastcgi_buffers              4 64k;
    fastcgi_busy_buffers_size    128k;
    fastcgi_temp_file_write_size 128k;

    gzip                on;
    gzip_buffers        16 8k;
    gzip_comp_level     5;
    gzip_http_version   1.0;
    gzip_min_length     1000;
    gzip_proxied        any;
    gzip_types

    text/css text/javascript text/xml text/plain text/x-component
    application/x-javascript application/javascript application/json application/xml application/rss+xml
    font/truetype font/opentype application/vnd.ms-fontobject
    image/svg+xml;
    gzip_vary           on;

    autoindex on;

    upstream php {
        server 127.0.0.1:9000;
    }

    upstream php_pool {
        ip_hash;
        server 127.0.0.1:9000 weight=1 max_fails=3 fail_timeout=10s;
        server 127.0.0.1:9001 weight=1 max_fails=3 fail_timeout=10s;
        server 127.0.0.1:9002 weight=1 max_fails=3 fail_timeout=10s;
        server 127.0.0.1:9003 weight=1 max_fails=3 fail_timeout=10s;
    }

    server {
        listen       127.0.0.1:80;
        server_name  localhost;
        root         D:/Server/www;

        log_not_found off;
        charset utf-8;

        access_log  D:/Server/logs/nginx/host.access.log  main;

        location / {
            index index.php index.html;
        }

        location /phpmyadmin/ {
            alias          D:/Server/apps/phpmyadmin;
            fastcgi_pass   php;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME $request_filename;
            fastcgi_param  REMOTE_ADDR $http_x_real_ip;
            include        D:/Server/bin/nginx/conf/fastcgi_params;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        location ~ \.php$ {
            try_files      $uri =404;
            fastcgi_pass   php;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  REMOTE_ADDR $http_x_real_ip;
            include        D:/Server/bin/nginx/conf/fastcgi_params;
        }

        location ~* ^.+.(gif|ico|jpg|jpeg|png|flv|swf|pdf|mp3|mp4|xml|txt|js|css)$ {
            expires 30d;
            add_header Vary Accept-Encoding;
        }

        if ($request_method !~ ^(GET|HEAD|POST)$ ) { return 405; }

        location ~ /(\.ht|\.git|\.svn) {
            access_log off;
            log_not_found off;
            deny  all;
        }
    }
}

来自 Nginx HTTP Server 书:

alias Context: location. Variables are accepted. alias is a directive that you place in a location block only. It assigns a different path for Nginx to retrieve documents for a specific request. As an example, consider the following configuration: http { server { server_name localhost; root /var/www/website.com/html; location /admin/ { alias /var/www/locked/; } } } When a request for http://localhost/ is received, files are served from the /var/www/website.com/html/ folder. However, if Nginx receives a request for http://localhost/admin/, the path used to retrieve the files is var/www/locked/. Moreover, the value of the document root directive (root) is not altered. This procedure is invisible in the eyes of dynamic scripts. Syntax: Directory (do not forget the trailing /) or file path

更新

@Richard Smith 建议将别名更改为 root 并将 C:/Server/apps/phpmyadmin/更改为 C:/Server/apps 并添加 ^~ 修饰符。现在我使用 root 而不是别名我可以将 SCRIPT_FILENAME 返回到 $document_root$fastcgi_script_name;

最佳答案

在您当前的配置中,任何具有 .php 扩展名的文件都由相同的位置 block 处理,这对于 laravel 来说很好,但对于 phpmyadmin 来说是致命的。

您的 phpmyadmin 位置 block 的优先级低于 .php 位置 block 。查看nginx chooses a location to process a request .

您可以使用 ^~ 修饰符为 phpmyadmin 位置 block 赋予比所有正则表达式位置 block 更高的优先级:

location ^~ /phpmyadmin/ {
    root D:/Server/apps;
    fastcgi_pass   php;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    ...
}

还有:root is more efficient aliasfastcgi_index 仅在 $fastcgi_script_name 上运行,因此您需要像上面那样更改 SCRIPT_FILENAME

关于php - Nginx 和 PHP-FPM - 权限被拒绝 - Windows,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34383639/

有关php - Nginx 和 PHP-FPM - 权限被拒绝 - Windows的更多相关文章

  1. ruby - 在 Ruby 程序执行时阻止 Windows 7 PC 进入休眠状态 - 2

    我需要在客户计算机上运行Ruby应用程序。通常需要几天才能完成(复制大备份文件)。问题是如果启用sleep,它会中断应用程序。否则,计算机将持续运行数周,直到我下次访问为止。有什么方法可以防止执行期间休眠并让Windows在执行后休眠吗?欢迎任何疯狂的想法;-) 最佳答案 Here建议使用SetThreadExecutionStateWinAPI函数,使应用程序能够通知系统它正在使用中,从而防止系统在应用程序运行时进入休眠状态或关闭显示。像这样的东西:require'Win32API'ES_AWAYMODE_REQUIRED=0x0

  2. ruby-on-rails - 如何优雅地重启 thin + nginx? - 2

    我的瘦服务器配置了nginx,我的ROR应用程序正在它们上运行。在我发布代码更新时运行thinrestart会给我的应用程序带来一些停机时间。我试图弄清楚如何优雅地重启正在运行的Thin实例,但找不到好的解决方案。有没有人能做到这一点? 最佳答案 #Restartjustthethinserverdescribedbythatconfigsudothin-C/etc/thin/mysite.ymlrestartNginx将继续运行并代理请求。如果您将Nginx设置为使用多个上游服务器,例如server{listen80;server

  3. ruby - 在 Windows 机器上使用 Ruby 进行开发是否会适得其反? - 2

    这似乎非常适得其反,因为太多的gem会在window上破裂。我一直在处理很多mysql和ruby​​-mysqlgem问题(gem本身发生段错误,一个名为UnixSocket的类显然在Windows机器上不能正常工作,等等)。我只是在浪费时间吗?我应该转向不同的脚本语言吗? 最佳答案 我在Windows上使用Ruby的经验很少,但是当我开始使用Ruby时,我是在Windows上,我的总体印象是它不是Windows原生系统。因此,在主要使用Windows多年之后,开始使用Ruby促使我切换回原来的系统Unix,这次是Linux。Rub

  4. Vscode+Cmake配置并运行opencv环境(Windows和Ubuntu大同小异) - 2

    之前在培训新生的时候,windows环境下配置opencv环境一直教的都是网上主流的vsstudio配置属性表,但是这个似乎对新生来说难度略高(虽然个人觉得完全是他们自己的问题),加之暑假之后对cmake实在是爱不释手,且这样配置确实十分简单(其实都不需要配置),故斗胆妄言vscode下配置CV之法。其实极为简单,图比较多所以很长。如果你看此文还配不好,你应该思考一下是不是自己的问题。闲话少说,直接开始。0.CMkae简介有的人到大二了都不知道cmake是什么,我不说是谁。CMake是一个开源免费并且跨平台的构建工具,可以用简单的语句来描述所有平台的编译过程。它能够根据当前所在平台输出对应的m

  5. 深度学习部署:Windows安装pycocotools报错解决方法 - 2

    深度学习部署:Windows安装pycocotools报错解决方法1.pycocotools库的简介2.pycocotools安装的坑3.解决办法更多Ai资讯:公主号AiCharm本系列是作者在跑一些深度学习实例时,遇到的各种各样的问题及解决办法,希望能够帮助到大家。ERROR:Commanderroredoutwithexitstatus1:'D:\Anaconda3\python.exe'-u-c'importsys,setuptools,tokenize;sys.argv[0]='"'"'C:\\Users\\46653\\AppData\\Local\\Temp\\pip-instal

  6. ruby - rbenv 安装权限被拒绝 - 2

    大家好,我正在尝试设置一个开发环境,并且我一直在关注以下教程:Linktotutorial我做得不是很好,除了最基本的版本控制内容外,我对终端命令没有任何实际经验。我点击了第一个链接并尝试运行source~/.bash_profile我得到了错误;mkdir:/usr/local/rbenv/shims:权限被拒绝mkdir:/usr/local/rbenv/versions:权限被拒绝现在每次我加载终端时都会出现错误。bash_profile的内容;exportPATH=/usr/local/rbenv/bin:$PATHexportRBENV_ROOT=/usr/local/rbe

  7. ruby-on-rails - 如何用不同的用户运行nginx主进程 - 2

    A/ctohttp://wiki.nginx.org/CoreModule#usermaster进程曾经以root用户运行,是否可以以不同的用户运行nginxmaster进程? 最佳答案 只需以非root身份运行init脚本(即/etc/init.d/nginxstart),就可以用不同的用户运行nginxmaster进程。如果这真的是你想要做的,你将需要确保日志和pid目录(通常是/var/log/nginx&/var/run/nginx.pid)对该用户是可写的,并且您所有的listen调用都是针对大于1024的端口(因为绑定(

  8. ruby - 如何在 Ruby 中执行 Windows CLI 命令? - 2

    我在目录“C:\DocumentsandSettings\test.exe”中有一个文件,但是当我用单引号编写命令时`C:\DocumentsandSettings\test.exe(我无法在此框中显示),用于在Ruby中执行命令,我无法这样做,我收到的错误是找不到文件或目录。我尝试用“//”和“\”替换“\”,但似乎没有任何效果。我也使用过系统、IO.popen和exec命令,但所有的努力都是徒劳的。exec命令还使程序退出,这是我不想发生的。提前致谢。 最佳答案 反引号环境就像双引号,所以反斜杠用于转义。此外,Ruby会将空格解

  9. ruby-on-rails - 为什么用户必须输入 7 位数的 Twitter PIN 才能授予我的应用程序访问权限? - 2

    我正在为我的用户实现一些ruby​​onrails代码推特内容。我正在创建正确的oauth链接...类似http://twitter.com/oauth/authorize?oauth_token=y2RkuftYAEkbEuIF7zKMuzWN30O2XxM8U9j0egtzKv但在我的测试帐户授予对twitter的访问权限后,它会弹出一个页面,上面写着“您已成功授予对.我不知道用户应该在哪里输入此PIN以及他们为什么必须这样做。我认为这不是必要的步骤。Twitter应该将用户重定向到我在应用程序设置中提供的回调URL。有谁知道为什么会这样?更新我找到了thisarticle声明我需

  10. ruby - rbenv:权限被拒绝 - 2

    我正在关注Ryan的RailsCast第339集。我已经安装了rbenv并且可以运行ruby-v。我退出了我的session,当我试图返回时(通过root的sudeployer,我得到了这个错误/home/deployer/.rbenv/bin/rbenv:line20:cd:/root:Permissiondenied这是rbenv文件:#!/usr/bin/envbashset-e[-n"$RBENV_DEBUG"]&&set-xresolve_link(){$(type-pgreadlinkreadlink|head-1)"$1"}abs_dirname(){localcwd="

随机推荐