Deploying to NGINX
Though Casdoor follows a front-end back-end separation architecture, in a production environment, the back-end program still provides static file services for front-end files. Hence, you can employ reverse proxy software like Nginx to proxy all traffic for the Casdoor domain and redirect it to the port monitored by the backend Go program.
In this chapter, you will learn how to use Nginx to reverse proxy your backend Go program and quickly start the Casdoor service.
1. Build front end static files
Assuming you have downloaded Casdoor and completed the necessary configuration (if not, refer to the Get started section), you only need to build the static files as follows:
- Yarn
- npm
yarn install && yarn run build
npm install && npm run build
2. Run the back-end program
go run main.go
Or, build it first:
go build && ./main
3. Configure and run Nginx
vim /path/to/nginx/nginx.conf
Then, add a server:
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;
}
}
Next, restart your Nginx process. Run:
nginx -s reload
4. Test
Visit http://YOUR_DOMAIN_NAME
in your favorite browser.