AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • Início
  • system&network
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • Início
  • system&network
    • Recentes
    • Highest score
    • tags
  • Ubuntu
    • Recentes
    • Highest score
    • tags
  • Unix
    • Recentes
    • tags
  • DBA
    • Recentes
    • tags
  • Computer
    • Recentes
    • tags
  • Coding
    • Recentes
    • tags
Início / server / Perguntas / 902024
Accepted
BentCoder
BentCoder
Asked: 2018-03-17 05:59:59 +0800 CST2018-03-17 05:59:59 +0800 CST 2018-03-17 05:59:59 +0800 CST

Nginx não servirá arquivos PHP de um servidor remoto

  • 772

Quando eu chamo o servidor NGINX, ele deve servir arquivos php armazenados em um servidor PHP remoto. Atualmente recebo 404 Not Found - nginx/1.10.3 (Ubuntu). Se eu mudar root /srv/www/sitepara root /var/www/htmlentão, ele serve com sucesso index.htmldo NGINX, então a solicitação nunca atinge o servidor PHP.

  • SERVIDOR PHP: 192.168.99.31 ( PHP 7.1.15)
  • SERVIDOR NGINX: 192.168.99.32 ( nginx version: nginx/1.10.3 (Ubuntu))

O servidor PHP é acessível a partir do servidor NGINX pela porta 9000, como visto abaixo, então não acho que haja problemas relacionados à conexão aqui.

vagrant@nginx:~$ nc -zv 192.168.99.31 9000
Connection to 192.168.99.31 9000 port [tcp/*] succeeded!

PHP

vagrant@php:~$ cat /etc/php/7.1/fpm/pool.d/www.conf

[www]
user                   = www-data
group                  = www-data

listen                 = 9000
listen.allowed_clients = 192.168.99.32
listen.owner           = www-data
listen.group           = www-data

pm = dynamic
pm.max_children        = 5
pm.start_servers       = 2
pm.min_spare_servers   = 1
pm.max_spare_servers   = 3

-

vagrant@php:~$ dpkg --list | grep php

ii  php-common                       1:60+ubuntu16.04.1+deb.sury.org+1
ii  php7.1                           7.1.15-1+ubuntu16.04.1+deb.sury.org+2
ii  php7.1-cgi                       7.1.15-1+ubuntu16.04.1+deb.sury.org+2
ii  php7.1-cli                       7.1.15-1+ubuntu16.04.1+deb.sury.org+2
ii  php7.1-common                    7.1.15-1+ubuntu16.04.1+deb.sury.org+2
ii  php7.1-fpm                       7.1.15-1+ubuntu16.04.1+deb.sury.org+2
ii  php7.1-json                      7.1.15-1+ubuntu16.04.1+deb.sury.org+2
ii  php7.1-mbstring                  7.1.15-1+ubuntu16.04.1+deb.sury.org+2
ii  php7.1-mcrypt                    7.1.15-1+ubuntu16.04.1+deb.sury.org+2
ii  php7.1-mysql                     7.1.15-1+ubuntu16.04.1+deb.sury.org+2
ii  php7.1-opcache                   7.1.15-1+ubuntu16.04.1+deb.sury.org+2
ii  php7.1-readline                  7.1.15-1+ubuntu16.04.1+deb.sury.org+2
ii  php7.1-zip                       7.1.15-1+ubuntu16.04.1+deb.sury.org+2

-

vagrant@php:~$ cat /srv/www/site/index.php 
<?php
echo 'Hello from PHP host'.PHP_EOL;

NGINX

vagrant@nginx:~$ cat /etc/nginx/sites-available/default

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /srv/www/site;
        index index.php index.html;
        server_name _;

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

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass 192.168.99.31:9000;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }

        location ~ /\.ht {
                deny all;
        }

        error_log /var/log/nginx/site_error.log;
        access_log /var/log/nginx/site_access.log;
}

-

vagrant@nginx:~$ cat /etc/nginx/snippets/fastcgi-php.conf

fastcgi_split_path_info ^(.+\.php)(/.+)$;
try_files $fastcgi_script_name =404;
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;
fastcgi_index index.php;
include fastcgi.conf;

-

vagrant@nginx:~$ cat /etc/nginx/fastcgi.conf

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
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_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  REQUEST_SCHEME     $scheme;
fastcgi_param  HTTPS              $https if_not_empty;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

fastcgi_param  REDIRECT_STATUS    200;
nginx
  • 2 2 respostas
  • 2982 Views

2 respostas

  • Voted
  1. Best Answer
    BentCoder
    2018-03-17T16:05:01+08:002018-03-17T16:05:01+08:00

    ORDENADO

    Então é tudo uma questão de mudar try_files $uri $uri/ =404;para try_files $uri $uri/ /index.php?$query_string;. Veja a versão limpa abaixo.

    ubuntu@nginx:~$ cat /etc/nginx/sites-available/default
    
    server {
        listen 80;
        listen [::]:80;
    
        root /srv/www/site;
    
        location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            set $path_info $fastcgi_path_info;
            fastcgi_param PATH_INFO $path_info;
            fastcgi_index index.php;
            include fastcgi.conf;
            fastcgi_pass 192.168.99.31:9000;
        }
    
        # Deny access to .htaccess files
        location ~ /\.ht {
            deny all;
        }
    
        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }
    
        error_log /var/log/nginx/site_error.log;
        access_log /var/log/nginx/site_access.log;
    }
    
    • 2
  2. Richard Smith
    2018-03-17T06:36:36+08:002018-03-17T06:36:36+08:00

    Você tem a declaração:

    try_files $fastcgi_script_name =404;
    

    Que testa a existência do arquivo na máquina local . Como você está tentando executar scripts PHP em alguma outra máquina, a try_filesinstrução provavelmente está forçando a resposta 404.

    Exclua a try_filesinstrução e confie na máquina remota para verificar a existência de arquivos de script e lidar com a exploração de solicitações não controladas corretamente.

    Ou espelhe a instalação em ambos os servidores.

    Veja este documento para saber mais.

    • 1

relate perguntas

Sidebar

Stats

  • Perguntas 205573
  • respostas 270741
  • best respostas 135370
  • utilizador 68524
  • Highest score
  • respostas
  • Marko Smith

    Você pode passar usuário/passar para autenticação básica HTTP em parâmetros de URL?

    • 5 respostas
  • Marko Smith

    Ping uma porta específica

    • 18 respostas
  • Marko Smith

    Verifique se a porta está aberta ou fechada em um servidor Linux?

    • 7 respostas
  • Marko Smith

    Como automatizar o login SSH com senha?

    • 10 respostas
  • Marko Smith

    Como posso dizer ao Git para Windows onde encontrar minha chave RSA privada?

    • 30 respostas
  • Marko Smith

    Qual é o nome de usuário/senha de superusuário padrão para postgres após uma nova instalação?

    • 5 respostas
  • Marko Smith

    Qual porta o SFTP usa?

    • 6 respostas
  • Marko Smith

    Linha de comando para listar usuários em um grupo do Windows Active Directory?

    • 9 respostas
  • Marko Smith

    O que é um arquivo Pem e como ele difere de outros formatos de arquivo de chave gerada pelo OpenSSL?

    • 3 respostas
  • Marko Smith

    Como determinar se uma variável bash está vazia?

    • 15 respostas
  • Martin Hope
    Davie Ping uma porta específica 2009-10-09 01:57:50 +0800 CST
  • Martin Hope
    kernel O scp pode copiar diretórios recursivamente? 2011-04-29 20:24:45 +0800 CST
  • Martin Hope
    Robert ssh retorna "Proprietário incorreto ou permissões em ~/.ssh/config" 2011-03-30 10:15:48 +0800 CST
  • Martin Hope
    Eonil Como automatizar o login SSH com senha? 2011-03-02 03:07:12 +0800 CST
  • Martin Hope
    gunwin Como lidar com um servidor comprometido? 2011-01-03 13:31:27 +0800 CST
  • Martin Hope
    Tom Feiner Como posso classificar a saída du -h por tamanho 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich O que é um arquivo Pem e como ele difere de outros formatos de arquivo de chave gerada pelo OpenSSL? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent Como determinar se uma variável bash está vazia? 2009-05-13 09:54:48 +0800 CST

Hot tag

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • Início
  • Perguntas
    • Recentes
    • Highest score
  • tag
  • help

Footer

AskOverflow.Dev

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve