2017-08-27 301 views
1

我的nginx的配置

文件的nginx/nginx.confguzzlehttp请求错误502 Nginx的设置

#user nobody; 
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  8080; 
     server_name localhost; 

     #charset koi8-r; 

     root /Users/My/Documents/web; 
     index index.php index.html index.htm; 

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

     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$ { 
      try_files $uri /index.php =404; 
      fastcgi_split_path_info ^(.+\.php)(/.+)$; 
      fastcgi_pass 127.0.0.1:9000; 
      fastcgi_index index.php; 
      include  fastcgi.conf; 
     } 

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

文件的nginx /服务器/ myhost.conf

# another virtual host using mix of IP-, name-, and port-based configuration 
server { 
    # SSL configuration 

    # Enable Nginx HTTP/2.0 Protocol 
    listen  8081 ssl http2 default_server; 
    listen [::]:8081 ssl http2 default_server; 
    server_name 127.0.0.1; 
    root /Users/My/Documents/web/star/public; 
    index index.php; 

    gzip   on; 
    gzip_types  text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript application/json; 
    gzip_comp_level 9; 

    if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})") { 
     set $year $1; 
     set $month $2; 
     set $day $3; 
    } 
    error_log /Users/My/Documents/web/star/storage/logs/error.log; 
    access_log /Users/My/Documents/web/star/storage/logs/access-$year-$month-$day.log main; 

    # SSL certificate configuration 
    ssl_certificate /Users/My/Documents/ssl/certs/nginx.crt; 
    ssl_certificate_key /Users/My/Documents/ssl/private/nginx.key; 

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 
    ssl_prefer_server_ciphers on; 
    ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5; 
    ssl_dhparam /Users/My/Documents/ssl/certs/dhparam.pem; 
    ssl_session_cache shared:SSL:20m; 
    ssl_session_timeout 180m; 
    resolver 8.8.8.8 8.8.4.4; 
    add_header Strict-Transport-Security "max-age=31536000; 
    #includeSubDomains" always; 

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

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 
    # 
    location ~ \.php$ { 
     try_files $uri $uri/ /index.php$is_args$args; 

     fastcgi_split_path_info ^(.+\.php)(/.+)$; 
     fastcgi_pass 127.0.0.1:9000; 
     fastcgi_index index.php; 
     fastcgi_intercept_errors on; 

     fastcgi_param SCRIPT_FILENAME  $document_root$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; 
    } 
} 

我的代码

我使用以下代码来请求任何网站,但也显示错误

$client = new GuzzleClient([ 
    'timeout' => 5.0, 
    'cookies' => true, 
    'headers' => [ 
     'User-Agent' => static::USER_AGENT 
    ], 
]); 

$crawler = $client->request('GET', 'https://google.com'); 
dd($crawler); 

我的错误

nginx的error.log中

2017年8月27日19时33分45秒[错误] 27427#0:* 54上游过早关闭的连接在读取响应头上游,客户端:127.0.0.1,服务器:127.0.0.1,请求:“GET/HTTP/2.0”,上游:“fastcgi://127.0.0.1:9000”,主机:“127.0.0.1:8081”

+0

只放一个回声在你的PHP页面,看看它是否有效 –

+0

它的作品,如果我添加phpinfo在路线/ web.php – Kerrick

回答

0

我使用的Mac - 高级系列,我只是备份到PHP 7.0然后工作....它与ngi无关NX。可能一些封装粉碎php上游

+0

一个更多的测试。我使用PHP 7.1的Docker工作。也许Mac版本的问题 – Kerrick