dongxiaoguang9108 2018-02-17 12:16
浏览 56

无法访问php文件nginx

I am completely new to nginx . I have project based on angular js which have a index.html, and on a certain event i perform a angular http request to x.php file and fetches the response from it. Its running perfect on my local system and a apache based private hosting server. I created a free tier ec2 instance and started a centos based linux instance on which i hosted the code and installed nginx . Here is my nginx config

server {
  listen        80;
  server_name  mydomain.co.in www.mydomain.co.in;

   location / {
     root   /var/www/html/indm;
     index  index.php index.html index.htm;
     try_files $uri/ $uri /index.php?$query_string =404;
   }
   location ~ \.php$ {
      try_files $uri $uri/ /index.php?q=$uri&$args =404;
      fastcgi_split_path_info ^(.+\.php)(/.+)$;
      fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      include fastcgi_params;
      add_header Access-Control-Allow-Origin *;
      proxy_set_header Access-Control-Allow-Origin $http_origin;
   }
   error_page  500 502 503 504  /50x.html;

At first it was giving me 500 gateway error when the http request was performed on that php file. I check in the XHR request.Here is the error in nginx error.log

[error] 17193#0: *2 rewrite or internal redirection cycle while internally redirecting to "/index.php", client: 42.111.38.254

I searched a bit and changed appended a "=404" to try uri statement. But now it redirect to a 404 . I want to run that php file. the server Nginx server is running php fpm is also running

Please help

  • 写回答

1条回答 默认 最新

  • dongnuo2879 2018-02-17 13:56
    关注

    The location ~ \.php$ block has no root. Move the root statement into the server block so that the same value is inherited by both location blocks.

    For example:

    server {
        ...
        root   /var/www/html/indm;
    
        location / {
            ...
        }
        location ~ \.php$ {
            ...
        }
        ...
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥100 求数学坐标画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站