Nginx에 Laravel 및 소켓 IO 배포

Nginx에 Laravel 및 소켓 IO 배포

nginx에서 소켓 io를 사용하는 Laravel 프로젝트를 배포했습니다.

서버 사양은 다음과 같습니다.

NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

여기 내 구성 파일이 있습니다.

server {
    listen       443 ssl;
    server_name  website.tld;
    proxy_pass_header Server;
    proxy_buffering off;
    server_tokens off;
    
    ssl_certificate      /etc/nginx/ssl/biz/ssl.crt;
    ssl_certificate_key  /etc/nginx/ssl/biz/ssl.key;

    ssl_session_cache shared:SSL:50m;
    ssl_session_timeout 5m;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options nosniff;
    proxy_cookie_path / "/; secure;";
    ssl_prefer_server_ciphers   on;
    server_name_in_redirect on;    
    proxy_buffer_size   128m;
    proxy_buffers   4 256m;
    proxy_busy_buffers_size   256m;



    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;
 
    root /home/laravel/public_html/public;
    index  index.php;

    # Requests for socket.io are passed on to Node on port 3000
    location /socket.io {
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto  https;
      proxy_set_header X-VerifiedViaNginx yes;
      proxy_set_header Host $http_host;
      proxy_set_header X-NginX-Proxy false;

      proxy_pass http://localhost:3000;
      proxy_redirect off;

      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
    }

    location / {
         try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$
    {
       # try_files $uri $uri/ /index.php?$args;
        try_files $uri /index.php$request_uri;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

하지만 에 액세스하면https://웹사이트:3000 브라우저의 출력 :

이 사이트는 보안 연결을 제공할 수 없습니다.website.tld가 잘못된 응답을 보냈습니다. ERR_SSL_PROTOCOL_ERROR

내 구성에 실수가 있나요?

답변1

웹사이트를 로드하기 위해 포트 번호를 지정할 필요가 없습니다. 그냥 https://website.example할 것입니다. 그 이유는 이제 기본 https 포트인 포트 443에서 웹 사이트를 제공하는 nginx가 있기 때문입니다. 그러나 nginx를 우회하고 https를 사용하여 직접적으로 소켓.io 서버에 액세스하려고 시도했는데 이는 말하지 않습니다. 포트 번호를 제거하면 대신 포트 443의 nginx에 연결됩니다.

또한 보안을 위해 악의적인 사용자가 nginx를 우회하여 직접 연결할 수 없도록 Socket.io 서버가 localhost의 연결만 수신하는지 확인해야 합니다.

관련 정보