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
- npm
yarn install && yarn run build
npm install && npm run build
Run the backend
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 konfigurieren
-
Add a
serverblock to your Nginx configuration. ReplaceYOUR_DOMAIN_NAMEwith 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;
}
} -
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
serverblock and serve Casdoor over HTTPS. OAuth 2.0 and OpenID Connect (OIDC) clients expect an HTTPS issuer in production. - Set
origininapp.confto the public URL of Casdoor.