Executando um site PHP com NGINX no MacOS

1

Eu usei este blog como base para criar um ambiente local para executar sites PHP no MacOS Sierra. Eu instalei o NGINX, PHP 7, PHP-FPM, MySQL e PhpMyAdmin. Todas as partes parecem estar funcionando:

Usando o padrão nginx.conf e executando: curl -IL http://127.0.0.1:8080 , recebo:

HTTP/1.1 200 OK
Server: nginx/1.12.1
Date: Tue, 22 Aug 2017 08:10:03 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 11 Jul 2017 13:24:27 GMT
Connection: keep-alive
ETag: "5964d18b-264"
Accept-Ranges: bytes

Com relação ao PHP-FPM, na execução: lsof -Pni4 | grep LISTEN | grep php , recebo:

php-fpm   13178 phil    6u  IPv4 0x2b2cdb4c34e4e2c3      0t0  TCP 127.0.0.1:9000 (LISTEN)
php-fpm   13181 phil    0u  IPv4 0x2b2cdb4c34e4e2c3      0t0  TCP 127.0.0.1:9000 (LISTEN)
php-fpm   13182 phil    0u  IPv4 0x2b2cdb4c34e4e2c3      0t0  TCP 127.0.0.1:9000 (LISTEN)

Eu também posso iniciar o MySQL, eu recebo:

mysql>

Usando o padrão nginx.conf , posso visitar o link e vejo o 'Bem vindo ao nginx!' tela de teste.

O problema surge quando eu edito meu nginx.conf . Aqui está como eu editei:

user  phil staff;
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   /Users/phil/sites/drupal/;
            index  index.php;
        }

    location ~ \.php {
            fastcgi_split_path_info ^(.+?\.php)(/.*)$;
            if (!-f $document_root$fastcgi_script_name) {
                return 404;
            }
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_param SCRIPT_FILENAME $request_filename;
            include fastcgi_params;
        }

        #error_page  404              /404.html;

        # 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 ~ \.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;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # 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;
    #    }
    #}
    include servers/*;
}

Agora, se eu executar brew services restart nginx e, em seguida, sudo nginx -t , obtenho:

nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful

... mas, se eu visitar o link , recebo Local host refused to connect .

Meu palpite é que é permissões e uso da porta 80, mas não tenho certeza do que fazer para que isso funcione.

Se eu fizer curl -IL http://127.0.0.1:80 , obtenho:

curl: (7) Failed to connect to 127.0.0.1 port 80: Connection refused

Obrigado.

    
por 24ma13wg 22.08.2017 / 11:25

1 resposta

0

A solução foi reiniciar o serviço NGINX com sudo .

sudo brew services restart nginx
    
por 22.08.2017 / 13:19

Tags