2021年4月9日星期五

Migrating from apache2 to nginx: server-sent event question

I've been trying to migrate my server from apache2 to nginx. Everything works fine on apache2, and most of them still work on nginx with the exception of server-sent events. Whenever there is an SSE, I get a 504 gateway timeout. I think it has to do with server's output buffering, but I'm not sure. I'll attach both my apache2 and nginx conf files below.

Here's my apache config, in /etc/apache2/sites-available/:

<IfModule mod_fcgid.c>      #      ### fcgi processes configuration      #      FcgidMaxRequestsPerProcess 1000      FcgidMinProcessesPerClass 0      FcgidMaxProcesses 100      FcgidProcessLifeTime 0        #      ### TimeOuts configuration      #      FcgidIdleTimeout 10        #      ### Scan Intervals configuration      #      FcgidBusyScanInterval 120      FcgidErrorScanInterval 5      FcgidZombieScanInterval 5      FcgidIdleScanInterval 5  </IfModule>      <VirtualHost *:80>      ### SET to 0!!! otherwise mod_fcgid will do it's own output buffering       ### by default it's 65536 and not 0      ### MUST be set if SSE used      OutputBufferSize 0        BusyTimeout 120        ## Set to big number if SSE used      ## This is the maximum period of time the module will      ## wait while trying to read from or write to a FastCGI application      IPCCommTimeout 120        ## Let FastCGI to catch a Broken Pipe, if the SSE subscription      ## was closed. E.g. browser or site was closed.      IdleTimeout 10        KeepAlive on      MaxKeepAliveRequests 1000      KeepAliveTimeout 10         ServerName localhost         DocumentRoot /var/www/yang         AllowEncodedSlashes On       AddHandler fcgid-script .fcgi         <Directory /var/www/yang>           SetHandler fcgid-script           Options Indexes FollowSymLinks ExecCGI           AllowOverride all           Order allow,deny           allow from all       </Directory>         <Directory /var/www/yang/.well-known>          SetHandler default-handler          ForceType 'application/xrd+xml'            Header unset Etag          Header unset Last-Modified          Header unset Accept-Ranges          Header set Cache-Control no-cache          Header merge Cache-Control no-store          Header set Pragma no-cache            ## Ony GET is allowed          <Limit POST PATCH DELETE PUT>              Order deny,allow              Deny from all          </Limit>            AllowOverride all          Order allow,deny          allow from all      </Directory>    </VirtualHost>      

The OutputBufferSize directive is the old name for FcgidOutputBufferSize directive, as documented here: https://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html#fcgidoutputbuffersize

Without this directive in my apache2 conf file, I get the same gateway timeout error that I get on nginx. This makes me believe that my nginx config needs its own equivalent of FcgidOutputBufferSize, but I haven't been able to find such directive. I've played with fastcgi_buffer_size directive for my nginx config file but it did not work.

Here is my nginx config file. I know it's incomplete in alot of places; I'm very new to nginx.

in /etc/nginx/sites-available/

    # Default server configuration  #  server {    listen 80 default_server;    listen [::]:80 default_server;          root /var/www/yang;    keepalive_requests 1000;    keepalive_timeout 10;    server_name localhost;      index index.html index.htm index.nginx-debian.html;      # need to install fcgiwrap to use SERVER    # set SCRIPT_FILENAME to the location of the SERVER program    location /SERVER {      include fastcgi_params;            fastcgi_param  SCRIPT_NAME SERVER;            fastcgi_param  SCRIPT_FILENAME /var/www/yang/SERVER;            fastcgi_pass unix:/var/run/fcgiwrap.socket;    }             location = /favicon.ico {            log_not_found off;    }      location /.well-known {      default_type application/xrd+xml;      etag off;      add_header Last-Modified "";      proxy_force_ranges off;      add_header Cache-Control 'no-cache, no store';      proxy_cache_bypass $http_pragma;    }      location / {      # First attempt to serve request as file, then      # as directory, then fall back to displaying a 404.      try_files $uri $uri/ =404;      }    }    

Basically I need to translate my apache2 config to my nginx config as closely as possible but I am lost on how to do that. This is something that was tasked to me all of a sudden and I still have a lot of learning to do on nginx, so I'd also appreciate any points on where to start to understand nginx configuration.

https://stackoverflow.com/questions/67029915/migrating-from-apache2-to-nginx-server-sent-event-question April 10, 2021 at 09:06AM

没有评论:

发表评论