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$ {
            ...
        }
        ...
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配