跳到主内容

Deploy Casdoor behind Nginx

This guide explains how to run Casdoor from source in production mode and proxy the traffic of your domain to it with Nginx.


Learning outcomes​

  • Build the Casdoor frontend into static files.
  • Run the Casdoor backend, which serves both the API and the frontend.
  • Proxy your domain to the backend with Nginx.

What you need​

  • Casdoor cloned and connected to a database. See Install the Casdoor server.
  • Nginx on the same server
  • A domain name that points to the server

Build the frontend​

In the web directory of the Casdoor repository, build the static files:

yarn install && yarn run build

运行后端​

In the repository root, run the backend. It serves the API and the built frontend on port 8000.

go run main.go

Alternatively, build a binary and run it:

go build && ./casdoor

配置Nginx​

  1. Add a server block to your Nginx configuration. Replace YOUR_DOMAIN_NAME with your domain.

    server {
    listen 80;
    server_name YOUR_DOMAIN_NAME;
    location / {
    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_redirect off;
    proxy_pass http://127.0.0.1:8000;
    }
    }
  2. Reload Nginx:

    nginx -s reload

Verify the result​

Open http://YOUR_DOMAIN_NAME in a browser. The Casdoor sign-in page appears.

Next steps​

  • Add a TLS certificate to the server block and serve Casdoor over HTTPS. OAuth 2.0 and OpenID Connect (OIDC) clients expect an HTTPS issuer in production.
  • Set origin in app.conf to the public URL of Casdoor.

See also​