P
P
P4YK2020-12-09 09:37:56
PHP
P4YK, 2020-12-09 09:37:56

Nginx is loading index.php, how to fix this?

When I enter localhost/index.php, it starts downloading it for me. How to fix it?
Here is the path: sudo nano /etc/nginx/sites-available/default

# Default server configuration
#
server {
        listen 80 default_server;
        listen [::]:80 default_server;

        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;

        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.php index.html index.htm index.nginx-debian.html;

        server_name 185.18.54.106;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ /index.php?$uri&$args;
        }

        # pass PHP scripts to FastCGI server
        #
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
        #
        #       # With php-fpm (or other unix sockets):
                fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        #       # With php-cgi (or other tcp sockets):
        #       fastcgi_pass 127.0.0.1:9000;
        #}

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

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
SKEPTIC, 2020-12-09
@P4YK

You just need to install php-fpm and set the path to the php-fpm socket in nginx.

A
Andrey Galkin, 2020-12-09
@socengel

you need to set proxy on php-fpm something like this

location ~ \.php$ {
    fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock;
    #fastcgi_pass    127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param DOCUMENT_ROOT /var/www/;
    fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name;
    fastcgi_param PATH_TRANSLATED /var/www$fastcgi_script_name;
    include fastcgi_params;
    fastcgi_param QUERY_STRING $query_string;
    fastcgi_param REQUEST_METHOD $request_method;
    fastcgi_param CONTENT_TYPE $content_type;
    fastcgi_param CONTENT_LENGTH $content_length;
    fastcgi_intercept_errors on;
    fastcgi_ignore_client_abort off;
    fastcgi_connect_timeout 60;
    fastcgi_send_timeout 180;
    fastcgi_read_timeout 180;
    fastcgi_buffer_size 128k;
    fastcgi_buffers 4 256k;
    fastcgi_busy_buffers_size 256k;
    fastcgi_temp_file_write_size 256k;
    }

M
My joy, 2020-12-09
@t-alexashka

Here is an example of a working configuration (without ssl), it may come in handy

server {
  
  listen 80;
  server_name mydomain.com;

  root /var/www/mydomain;
  index index.php;

  error_log /var/www/logs/mydomain.error.log;
  access_log /var/www/logs/mydomain.access.log;

  location / {
    try_files $uri $uri/ /index.php?$args;
  }

  location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php7.1-fpm.sock;
  }

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

To avoid errors - add a folder logsto/var/www

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question