Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Css doesn't load - Nginx Deployment #3283

Closed
merlinfuchs opened this issue Sep 23, 2018 · 8 comments
Closed

Css doesn't load - Nginx Deployment #3283

merlinfuchs opened this issue Sep 23, 2018 · 8 comments

Comments

@merlinfuchs
Copy link

merlinfuchs commented Sep 23, 2018

Long story short

Im trying to deplo my aiohttp server with nginx. This is my configuration of nginx:

user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
  worker_connections 1024;
}

http {
  include /etc/nginx/mime.types;

  server {
    listen 80;
    client_max_body_size 4G;

    server_name bots.discord.club;

    location / {
      proxy_set_header Host $http_host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_redirect off;
      proxy_buffering off;
      proxy_pass https://aiohttp;
    }

    location /static {
      root /var/www/html;
    }

  }

  upstream aiohttp {
    # fail_timeout=0 means we always retry an upstream even if it failed
    # to return a good HTTP response

    # Unix domain servers
    # server unix:/tmp/example_1.sock fail_timeout=0;
    # server unix:/tmp/example_2.sock fail_timeout=0;
    # server unix:/tmp/example_3.sock fail_timeout=0;
    # server unix:/tmp/example_4.sock fail_timeout=0;

    # Unix domain sockets are used in this example due to their high performance,
    # but TCP/IP sockets could be used instead:
    server 127.0.0.1:8081 fail_timeout=0;
    # server 127.0.0.1:8082 fail_timeout=0;
    # server 127.0.0.1:8083 fail_timeout=0;
    # server 127.0.0.1:8084 fail_timeout=0;
  }
}

Everything works fine, beside that css from the static route isnt working.

image

It seems like nginx returns it as text/plain. I know this is probably a problem with nginx, but they wasnt able to help me, so I ask here.

Expected behaviour

Css should load.

Actual behaviour

Css doesn't load.

Steps to reproduce

user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
  worker_connections 1024;
}

http {
  include /etc/nginx/mime.types;

  server {
    listen 80;
    client_max_body_size 4G;

    server_name bots.discord.club;

    location / {
      proxy_set_header Host $http_host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_redirect off;
      proxy_buffering off;
      proxy_pass https://aiohttp;
    }

    location /static {
      root /var/www/html;
    }

  }

  upstream aiohttp {
    # fail_timeout=0 means we always retry an upstream even if it failed
    # to return a good HTTP response

    # Unix domain servers
    # server unix:/tmp/example_1.sock fail_timeout=0;
    # server unix:/tmp/example_2.sock fail_timeout=0;
    # server unix:/tmp/example_3.sock fail_timeout=0;
    # server unix:/tmp/example_4.sock fail_timeout=0;

    # Unix domain sockets are used in this example due to their high performance,
    # but TCP/IP sockets could be used instead:
    server 127.0.0.1:8081 fail_timeout=0;
    # server 127.0.0.1:8082 fail_timeout=0;
    # server 127.0.0.1:8083 fail_timeout=0;
    # server 127.0.0.1:8084 fail_timeout=0;
  }
}

Your environment

Ubuntu 16.04 LTS 64bit,
Nginx 1.10.3,
aiohttp 3.4.4

@asvetlov
Copy link
Member

GitMate.io thinks possibly related issues are #552 (More information about deployment?), #1842 (Can not load response cookies...), #3075 (trust_env doesn't works), #234 (Add note about production deployment), and #139 (Cookies doesn't shared between requests).

@merlinfuchs merlinfuchs changed the title Css doesn't load - Naginx Deployment Css doesn't load - Nginx Deployment Sep 23, 2018
@asvetlov asvetlov added the bug label Sep 23, 2018
@kxepal
Copy link
Member

kxepal commented Sep 23, 2018

This isn't aiohttp issue, but nginx misconfiguration. Check you nginx error log for any file read errors. Make sure request for static location hit nginx, but not aiohttp. Your configuration perfectly works for me (1.12.2).

@merlinfuchs
Copy link
Author

I already checked all nginx logs. The only thing I have is the output of the chrome console. (Screenshot above).
The file gets loaded from nginx but with the wrong header "text/plain" (should be text/css)

@kxepal
Copy link
Member

kxepal commented Sep 23, 2018

What the response will be if you request your css via curl? Will nginx send you correct Content-Type header?

@merlinfuchs
Copy link
Author

Ok, wtf. Now it randomly works. Did not change anything ...
Thank You anyway!

@MyNameIsCosmo
Copy link

MyNameIsCosmo commented Sep 23, 2018

Perhaps it's a cache issue?
I'd check nginx proxy caching configurations.

Maybe relevant:
https://stackoverflow.com/questions/6236078/how-to-clear-the-cache-of-nginx

@merlinfuchs
Copy link
Author

Yeah that was probably the issue. Thank You all.

@lock
Copy link

lock bot commented Oct 28, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a [new issue] for related bugs.
If you feel like there's important points made in this discussion, please include those exceprts into that [new issue].
[new issue]: https://github.com/aio-libs/aiohttp/issues/new

@lock lock bot added the outdated label Oct 28, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants