0

I have been looking around for a fix for hours now but nothing seems to do. It loads HTML files just fine, but when it comes to PHP files, it gives me this error. Sometimes it also gives me 405 error but I think I fixed that. and sometimes it starts to download the PHP file instead of executing it.

Here is the nginx.conf file:

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
  worker_connections  1024;
}


http {
include       mime.types;
default_type  application/octet-stream;

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

#access_log  logs/access.log  main;

sendfile        on;
#tcp_nopush     on;

#keepalive_timeout  0;
keepalive_timeout  65;

#gzip  on;

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    location / {
        root   html;
        index  index.html index.htm;
    }

    #error_page  404              /404.html;
    
    # To allow POST on static pages
    error_page  405     =200 $uri;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ C:/php {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        root           html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        include        fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}


# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
#    listen       8000;
#    listen       somename:8080;
#    server_name  somename  alias  another.alias;

#    location / {
#        root   html;
#        index  index.html index.htm;
#    }
#}


# HTTPS server
#
#server {
#    listen       443 ssl;
#    server_name  localhost;

#    ssl_certificate      cert.pem;
#    ssl_certificate_key  cert.key;

#    ssl_session_cache    shared:SSL:1m;
#    ssl_session_timeout  5m;

#    ssl_ciphers  HIGH:!aNULL:!MD5;
#    ssl_prefer_server_ciphers  on;

#    location / {
#        root   html;
#        index  index.html index.htm;
#    }
#}

}

I would very much appreciate any help

mdja123cs
  • 21
  • 3
  • Try changing [worker_processes](http://nginx.org/en/docs/ngx_core_module.html#worker_processes) to `auto`, and see if that makes a change. Otherwise, enable logging `error_log logs/error.log;` and look for errors in the logfile – Luuk Feb 14 '21 at 16:35
  • Still the same problem. Here is what the log file says: 2021/02/14 16:43:09 [error] 16948#10464: *15 connect() failed (10061: No connection could be made because the target machine actively refused it) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "localhost" – mdja123cs Feb 14 '21 at 16:43
  • It looks like the `fastcgi_pass` is incorrect, see: https://stackoverflow.com/questions/21909860/access-denied-on-nginx-and-php – Luuk Feb 14 '21 at 16:50
  • What does fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php5-fpm.sock; do? – mdja123cs Feb 14 '21 at 17:02
  • Forgot to also say that I'm working on a Windows machine – mdja123cs Feb 14 '21 at 17:02
  • see docs: http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html and http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_split_path_info – Luuk Feb 14 '21 at 18:13

0 Answers0