nagadomi / nunif

Misc; latest version of waifu2x; 2D video to stereo 3D video conversion
MIT License
1.58k stars 142 forks source link

Nginx got 400 Bad Request #228

Closed Ives-Natsume closed 2 months ago

Ives-Natsume commented 2 months ago

Hardware: Raspberry Pi 5 8GB RAM OS: Ubuntu server 20.04 LTS

python -m waifu2x.web --bind-addr 0.0.0.0 --port 8812 works fine on my machine.

After successfully loaded main page on my Nginx server, I got 400 Bad Request when I tried to upscale the pic:

400 Bad Request
Request Header Or Cookie Too Large
nginx/1.24.0 (Ubuntu)

And the error.log was clean. I have tried to enable larger size of client header buffers for the page, but it still didn't work.

Here is my page configuration file:

map $http_accept_language $lang {
  default en;
  ~ja ja;
  ~ru ru;
  ...
  ~en en;
}

#limit_req_zone $limit_req_key  zone=one:128m   rate=10r/m;
server  {
        listen 1002;
        server_name 192.168.137.2;

        access_log  /var/log/nginx/waifu2x-access.log;
        error_log     /var/log/nginx/waifu2x-error.log;

        root   /home/metasequoiani/server/nunif-master/waifu2x/web/public_html;

        try_files $uri $uri/index.$lang.html $uri/index.html @api;

        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_read_timeout 160;

        client_max_body_size 64M;
        client_header_buffer_size 4k;
        large_client_header_buffers 4 16k;

        location ~ ^/(apple-touch-icon|browserconfig|mstile)(.*)\.(png|xml|ico)$ {
            return 204;
        }
        location @api {
            #limit_req zone=one burst=3;
            set $limit_req_key $binary_remote_addr;
            if ($request_uri = "/recaptcha_state.json") {
                set $limit_req_key "";
            }
            proxy_pass http://192.168.137.2:1002;
        }
        listen 80;
}
nagadomi commented 2 months ago

two listen ports listen 80; and listen 1002; are specified, and proxy_pass http://192.168.137.2:1002; can cause infinite loop for listen 1002;. is it not http://localhost:8812/ ?

server_name 192.168.137.2;

Perhaps this does not work. If you suspect that is the cause, try server_name _ ;


nginx on https://waifu2x.net/ I just add

keepalive_timeout 65;    
client_max_body_size 5M; 

to /etc/nginx.conf http {} context. server config is almost the same as https://github.com/nagadomi/nunif/blob/master/waifu2x/web/appendix/waifu2x.nginx.conf

Ives-Natsume commented 2 months ago

Hi, thank you for your advise. I'm freshman in network but fortunately it finally worked. I have to set longer survival time because waifu2x takes longer time to run the task on my Pi.

And I've also deployed unlimited version on Nginx. Great thanks to your work!

Wish you a nice day :)