获取ERR_CONNECTION_TIMED_OUT Laravel回显服务器

时间:2019-07-16 07:51:26

标签: node.js nginx socket.io laravel-echo

Laravel echo在localhost上有效,但在使用cloudflare ssl的生产中则无效。我得到连接超时。

我的配置如下。

laravel echo服务器json:

{
        "authHost": "https://example.com",
        "authEndpoint": "/broadcasting/auth",
        "clients": [
                {
                        "appId": "xxxxxxxxx",
                        "key": "xxxxxxxxxxxxx"
                }
        ],
        "database": "redis",
        "databaseConfig": {
                "redis": {},
                "sqlite": {
                        "databasePath": "/database/laravel-echo-server.sqlite"
                }
        },
        "devMode": false,
        "host": "localhost",
        "port": "6001",
        "protocol": "https",
        "socketio": {},
        "sslCertPath": "/etc/ssl/certs/cert.pem",
        "sslKeyPath": "/etc/ssl/private/key.pem",
        "sslCertChainPath": "",
        "sslPassphrase": "",
        "subscribers": {
                "http": true,
                "redis": true
        },
        "apiOriginAllow": {
                "allowCors": true,
                "allowOrigin": "https://example.com:70",
                "allowMethods": "GET, POST",
                "allowHeaders": "Origin, Content-Type, X-Auth-Token, X-Requested-With, Accept, Authorization, X-CSRF-TOKEN, X-Socket-Id"
        }
}

这是我的整个Nginx配置:

server {
    listen 80;
    listen [::]:80;
    server_name example.com www.example.com;
    return 302 https://$server_name$request_uri;
    #rewrite     ^(.*)   https://domain$1 permanent; 
}
server {
    #SSL configuration

    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    ssl on;
    ssl_certificate /etc/ssl/certs/cert.pem;
    ssl_certificate_key /etc/ssl/private/key.pem;

     root /var/www/example/public;
     index index.php;

    client_max_body_size 100M;

    charset   utf-8;
    gzip on;
    gzip_vary on;
    gzip_disable "msie6";
    gzip_comp_level 6;
    gzip_min_length 1100;
    gzip_buffers 16 8k;
    gzip_proxied any;
    gzip_types
        text/plain
        text/css
        text/js
        text/xml
        text/javascript
        application/javascript
        application/x-javascript
        application/json
        application/xml
        application/xml+rss;
location / {
          try_files $uri $uri/ /index.php?$query_string;
    }

location /socket.io {
     proxy_pass http://localhost:6001;
     proxy_redirect off;
     proxy_http_version 1.1;
     proxy_set_header Upgrade $http_upgrade;
     proxy_set_header Connection "Upgrade";
 }
location ~ \.php$ {
        #include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.3-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        #fastcgi_read_timeout 300; 
    }
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc|svg|woff|woff2|ttf)\$ {
      expires 1M;
      access_log off;
      add_header Cache-Control "public";
    }
location ~* \.(?:css|js)\$ {
      expires 7d;
      access_log off;

当我运行laravel-echo-server start 我得到

    ✔  Running at localhost on port 6001
    ✔  Channels are ready.
    ✔  Listening for http events...
    ✔  Listening for redis events...

在前端控制台上,我得到连接超时。如果我将laravel echo设置为dev模式,则可以在终端中获取事件,但仍在前端控制台上连接超时。

似乎是nginx部分的配置错误。

那我该怎么做才能使它工作呢?

0 个答案:

没有答案