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 nginx.conf padrão 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

Em relação ao PHP-FPM, em execução:, lsof -Pni4 | grep LISTEN | grep phprecebo:

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)

Também posso iniciar o MySQL, recebo:

mysql>

Usando o nginx.conf padrão , posso visitar http: // localhost: 8080 / e vejo o 'Bem-vindo ao nginx!' tela de teste.

O problema surge quando eu edito meu nginx.conf . Aqui está como eu o 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 nginxe sudo nginx -t, em seguida , recebo:

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 http: // localhost / , recebo Local host refused to connect.

Meu palpite é que são as permissões e o uso da porta 80, mas não sei o que fazer para que isso funcione.

Se sim curl -IL http://127.0.0.1:80, recebo:

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

Obrigado.


fonte

Respostas:

0

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

sudo brew services restart nginx

fonte