簡體   English   中英

無法訪問php文件nginx

[英]unable to access php file nginx

我對nginx完全陌生。 我有一個基於帶有index.html的angular js的項目,並且在某個事件中,我對x.php文件執行一個angular http請求並從中獲取響應。 它在我的本地系統和基於apache的私人托管服務器上運行完美。 我創建了一個免費的ec2實例,並啟動了一個基於centos的linux實例,在該實例上托管了代碼並安裝了nginx。 這是我的nginx配置

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;

起初,在該php文件上執行http請求時,它給了我500個網關錯誤。 我檢查了XHR請求。這是nginx error.log中的錯誤

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

我搜索了一下並更改了附加的“ = 404”以嘗試uri語句。 但是現在它重定向到404。 我想運行該php文件。 服務器Nginx服務器正在運行php fpm也正在運行

請幫忙

location ~ \\.php$塊沒有根。 root語句移到server塊中,以便兩個location塊都繼承相同的值。

例如:

server {
    ...
    root   /var/www/html/indm;

    location / {
        ...
    }
    location ~ \.php$ {
        ...
    }
    ...
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM