简体   繁体   English

用php-fpm7.4配置nginx 1.18

[英]Configuration nginx 1.18 with php-fpm7.4

I want to run php under nginx, I have some difficulties.我想在nginx下运行php,遇到了一些困难。 I'm almost done, however, I have an error 502, I don't know why.我快完成了,但是,我有一个错误 502,我不知道为什么。

I have Nginx 1.18, php 7.4.x with fpm.我有带 fpm 的 Nginx 1.18、php 7.4.x。 I created a php file in: /usr/share/nginx/html/info.php, however when I am on it, I have an error 502. Here is the file I have for the default conf:我在 /usr/share/nginx/html/info.php 中创建了一个 php 文件,但是当我使用它时,出现错误 502。这是我为默认 conf 设置的文件:

server {服务器 {

    listen 80;
    root /usr/share/nginx/html;
    index index.php index.html index.htm index.nginx-debian.html;
    server_name localhost;

    location / {
            try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
            fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
    }

    location ~ /\.ht {
            deny all;
    }

} }

I have seen this line in some cases, however when I do "nginx -t" it fails.在某些情况下我已经看到了这条线,但是当我执行“nginx -t”时它失败了。

include snippets / fastcgi-php.conf;包括片段/fastcgi-php.conf;

I looked carefully, everything works locally, everything works.我仔细看了看,一切正常,一切正常。 I do not understand.我不明白。

In your post above you have server_name example.com.在您上面的帖子中,您有 server_name example.com。 Check if you have the right server name there.检查那里是否有正确的服务器名称。 Also, make sure your application server is running because nginx is unable to reach that's why you are seeing 502另外,请确保您的应用程序服务器正在运行,因为 nginx 无法访问这就是您看到 502 的原因

The problem is having more than 1 config file in /etc/php/7.4/fpm/pool.d问题是在 /etc/php/7.4/fpm/pool.d 中有超过 1 个配置文件

   usr@server:/etc/php/7.4/fpm/pool.d$ ls
      www.conf  foor-php-fpm.conf  bar-php-fpm.conf.bak
   

Solution解决方案

Step 1: Remove or rename any other.conf files and leave only www.conf第 1 步:删除或重命名任何 other.conf 文件,只保留 www.conf

usr@server:/etc/php/7.4/fpm/pool.d$ sudo mv other-php-fpm.conf other-php-fpm.conf.bak2

Step 2: systemctl restart php7.4-fpm.service第二步: systemctl restart php7.4-fpm.service

Done!完毕!

user@server:~$ systemctl status php7.4-fpm.service

    ● php7.4-fpm.service - The PHP 7.4 FastCGI Process Manager
         Loaded: loaded (/lib/systemd/system/php7.4-fpm.service; enabled; vendor preset: enabled)
         Active: active (running) since Thu 2020-12-31 16:16:22 UTC; 6s ago
           Docs: man:php-fpm7.4(8)
        Process: 381508 ExecStartPost=/usr/lib/php/php-fpm-socket-helper install /run/php/php-fpm.sock /etc/php/7.4/fpm/pool.d/www.conf 74 (code=exited, status=0/SUCCESS)
       Main PID: 381487 (php-fpm7.4)
         Status: "Ready to handle connections"
          Tasks: 3 (limit: 4568)
         Memory: 12.1M
         CGroup: /system.slice/php7.4-fpm.service
                 ├─381487 php-fpm: master process (/etc/php/7.4/fpm/php-fpm.conf)
                 ├─381506 php-fpm: pool www
                 └─381507 php-fpm: pool www

This solution applies to php-fpm-7.2 as well.此解决方案也适用于 php-fpm-7.2。

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

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