duanaixuan7385 2016-10-29 23:40
浏览 189
已采纳

nginx(MAMP)在index.php上返回404

I'm trying to use nginx in MAMP but for some reason i can't view any .php file it always returns a 404.

I've got not problem with .html files.

Does someone know what's causing this and how i could solve this ?

My nginx.conf:

#user                         admin staff;
worker_processes             2;

pid        c:/MAMP/bin/nginx/pid/nginx.pid;

events {
    worker_connections       1024;
}

http {
    include                  mime.types;
    default_type             text/html;
    gzip                     on;
    gzip_types               text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon;

    sendfile                 on;

    server {
        listen               80 default_server;

        # MAMP DOCUMENT_ROOT !! Don't remove this line !!
        root                 "C:/MAMP/htdocs/";

        access_log  c:/MAMP/logs/nginx_access.log;

        error_log  c:/MAMP/logs/nginx_error.log;

        location / {
            root C:\Git;
            index index.php index.html;
            autoindex on;
        }

        location ~* /MAMP(.*)$ {
            root             C:/MAMP/bin;
            index            index.php;

            location ~ \.php$ {
                try_files        $uri =404;
                fastcgi_pass     127.0.0.1:9100;
                fastcgi_param    SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include          fastcgi_params;
            }
        }

        location ~* /phpMyAdmin(.*)$ {
            root             C:/MAMP/bin;
            index            index.php;

            location ~ \.php$ {
                try_files        $uri =404;
                fastcgi_pass     127.0.0.1:9100;
                fastcgi_param    SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include          fastcgi_params;
            }
        }

        location ~* /phpLiteAdmin(.*)$ {
            root             C:/MAMP/bin;
            index            phpliteadmin.php index.php;

            location ~ \.php$ {
                try_files        $uri =404;
                fastcgi_pass     127.0.0.1:9100;
                fastcgi_param    SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include          fastcgi_params;
            }
        }

        location ~* /SQLiteManager(.*)$ {
            root             C:/MAMP/bin;
            index            index.php;

            location ~ \.php$ {
                try_files        $uri =404;
                fastcgi_pass     127.0.0.1:9100;
                fastcgi_param    SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include          fastcgi_params;
            }
        }

        #location /icons {
        #   alias /Applications/MAMP/Library/icons;
        #   autoindex on;
        #}

        #location /favicon.ico {
        #   alias /Applications/MAMP/bin/favicon.ico;
        #    # log_not_found off;
        #    # access_log off;
        #}

        location ~ \.php$ {
            try_files        $uri =404;
            fastcgi_pass     127.0.0.1:9100;
            fastcgi_param    SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include          fastcgi_params;
        }

        #location ~ /\. {
        #   deny all;
        #}

        # location ~* \.(gif|jpg|png|pdf)$ {
        #   expires          30d;
        # }

        # location = /robots.txt {
        #   allow all;
        #   log_not_found off;
        #   access_log off;
        # }

        # location ~* \.(txt|log)$ {
        #   allow 127.0.0.1;
        #   deny all;
        # }

        # location ~ \..*/.*\.php$ {
        #   return 403;
        # }

        #location /nginx_status {
        #   stub_status      on;
        #   access_log       off;
        #   allow            127.0.0.1;
        #   deny             all;
        #}
    }
}
  • 写回答

1条回答 默认 最新

  • dougu4027 2016-10-30 02:23
    关注

    Deep recommended I check the nginx logs so I did, I found the following line:

    [error] 14468#14504: *12 directory index of "C:/MAMP/htdocs/" is forbidden, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost"
    

    I remembered I changed the Document_Root in MAMP itself but never did this in my nginx.conf

    After changing the Document_Root in the nginx.conf the .php files worked :)

    The line that I changed to the real Document_Root:

    # MAMP DOCUMENT_ROOT !! Don't remove this line !!
    root                 "C:/MAMP/htdocs/";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 有偿,谁有移远的EC200S固件和最新的Qflsh工具。
  • ¥15 找一个QT页面+目标识别(行人检测)的开源项目
  • ¥15 有没有整苹果智能分拣线上图像数据
  • ¥20 有没有人会这个东西的
  • ¥15 cfx考虑调整“enforce system memory limit”参数的设置
  • ¥30 航迹分离,航迹增强,误差分析
  • ¥15 Chrome Manifest扩展引用Ajax-hook库拦截请求失败
  • ¥15 用Ros中的Topic通讯方式控制小乌龟的速度,走矩形;编写订阅器代码
  • ¥15 LLM accuracy检测
  • ¥15 pycharm添加远程解释器报错