hestiacp custom config for api.krishit.com
Best Solution: Create a Custom Proxy Template
Instead of modifying the generated config, create your own template.
1. Copy the existing templates
cd /usr/local/hestia/data/templates/web/nginx
cp default.tpl api-node.tpl
cp default.stpl api-node.stpl
2. Edit api-node.stpl
Replace this:
location / {
proxy_ssl_server_name on;
proxy_ssl_name $host;
proxy_pass https://%ip%:8443;
}
with:
location / {
if ($request_method = OPTIONS) {
add_header Access-Control-Allow-Origin "https://hrms.krishit.com" always;
add_header Access-Control-Allow-Credentials "true" always;
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS" always;
add_header Access-Control-Allow-Headers "Authorization, Content-Type, Accept, Origin, X-Requested-With" always;
return 204;
}
proxy_pass http://127.0.0.1:5000;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
add_header Access-Control-Allow-Origin "https://hrms.krishit.com" always;
add_header Access-Control-Allow-Credentials "true" always;
}
Add this immediately after it:
location /socket.io/ {
proxy_pass http://127.0.0.1:5000/socket.io/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
3. Remove this line
Delete:
proxy_hide_header Upgrade;
Otherwise WebSockets won't work.
4. Do the same in api-node.tpl
Replace the HTTP proxy to :8080 with:
proxy_pass http://127.0.0.1:5000;
and add the same socket.io location (without the SSL-specific directives).
5. Assign the template
v-change-web-domain-proxy-tpl api.krishit api.krishit.com api-node
v-rebuild-web-domain api.krishit api.krishit.com
nginx -t
systemctl reload nginx
Comments
Post a Comment