简体   繁体   English

php 正在下载而不是加载

[英]php is being downloaded instead of being loaded

I got a nginx docker container which actually works.我得到了一个实际工作的 nginx docker 容器。 Because when i do curl localhost:7070 on my host i get the content of the site as return.因为当我在我的主机上执行curl localhost:7070时,我会得到站点的内容作为返回。 Then i made a config for nginx on my host, the problem is when i try to open the site in a browser it downloads the php file.然后我在我的主机上为 nginx 进行了配置,问题是当我尝试在浏览器中打开该站点时,它会下载 php 文件。 I will sahre both configs of host nginx and docker nginx.我将介绍主机 nginx 和 docker nginx 的两个配置。

Nginx host conf: Nginx 主机配置:

    server {
            #listen 80 default_server;
            #listen [::]:80 default_server;
    
            # SSL configuration
           
             listen 7171 ssl default_server;
             listen [::]:7171 ssl default_server;    
            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 SERVERNAME;
    
            location / {
                proxy_pass         http://127.0.0.1:7070;
                #proxy_redirect     off;
                #proxy_set_header   Host $host;
                #proxy_set_header   X-Real-IP $remote_addr;
                #proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
                #proxy_set_header   X-Forwarded-Host $server_name;
            }
}

nginx docker conf: nginx docker 配置:

server {
    listen 80;

    server_name default_server;
    root /usr/share/nginx/selfoss;

    index index.php index.html;

    location ~* \ (gif|jpg|png) {
        expires 30d;
    }

    location ~ ^/(favicons|thumbnails)/.*$ {
        try_files $uri /data/$uri;
    }

    location ~* ^/(data\/logs|data\/sqlite|config\.ini|\.ht) {
        deny all;
    }

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

I know alittle about nginx normal config but im noob at php so what is the thing that im missing here?我对 nginx 正常配置知之甚少,但我在 php 是新手,所以我在这里缺少什么?

I have seen posts about php-fpm and fastcgi but i have no clue ho or where to do that config changes.我看过关于 php-fpm 和 fastcgi 的帖子,但我不知道如何或在哪里进行配置更改。

You are missing a configured PHP-FPM in your Nginx-Config and of course a running PHP-FPM (inside the same Docker-Container or in a separate Docker-Container).您在 Nginx-Config 中缺少配置的 PHP-FPM,当然还有正在运行的 PHP-FPM(在同一个 Docker-Container 或单独的 Docker-Container 中)。

Example Nginx-Config inside your server{} section server{}部分内的示例 Nginx-Config

location ~ \.php {
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_buffers 16 16k;
        fastcgi_buffer_size 32k;
        include fastcgi_params;

        proxy_read_timeout 300;
        fastcgi_read_timeout 300;

        fastcgi_pass unix:/var/run/sockets/php/www.sock;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM