Who can tell me about Django's configuration?

I am from China,

I have a Nginx configuration file (this file is used with uwsgi, port 80),

server {
listen 80;
server_name nocmt.com;

location /static/ {
    root /home/suly;
}
location / {
    include         uwsgi_params;
    uwsgi_pass      unix:/home/suly/suly.sock;
}

}
server {
listen 80;
server_name www.nocmt.com;
return 301 http://nocmt.com$request_uri;
}

please help me modify the caddy’s configuration file, thank you!

My personal website: http: //nocmt.com

Hi @nocmt, welcome to the Caddy community!

The Caddy examples repository has a small entry for Django, which I believe is still correct.

Because Caddy doesn’t have uWSGI functionality, you’ll need some other server to run your script, and then proxy to it via Caddy. In the example, Gunicorn is used.

Thank you for your reply, I checked the link you sent, perhaps I can try to use uwsgi start the project, with caddy monitoring port 80, if successful, I will release a tutorial.

I’ve been looking into using Caddy as a proxy for Django. What I found is that the example isn’t working with the latest version of Caddy. Now I’m a complete beginner with Caddy, but I got this working:

domain.tld {
    proxy / localhost:8000 {
        header_upstream Host {host}
        header_downstream X-Forwarded-Proto {scheme}
        except /media /static
    }

    root /var/www/project/folder
}

Is this correct or have I missed something?

I don’t think the second one is meant to be a header_downstream (you’re sending that back to the client that way).

The easiest and simplest way is actually to use the transparent preset for the proxy directive, which comes with a few headers useful for backends (including Host and X-Forwarded-Proto), and would have been updated along with the changing standard anyway.

Here’s how I’d write that example out fresh:

example.com {
  root /var/www/project/folder
  proxy / localhost:8000 {
    transparent
    except /media /static
  }
}

https://caddyserver.com/docs/proxy

Thanks, transparent looks right :slight_smile: Don’t know why i set it to downstream.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.