Connecting a domain to the CRYSTAL v1.0 project
February 28
upd: July 25
Contents:
1. Connect to your domain, public IP address of the VM, in the settings of the domain operator.
2. Editing the file - 'crystal', in the 'sites-available' folder.
Replace the IP address in the 'crystal' file, in line 4 - 'server_name', with your domain, as in the example below.
Enter the command:
nano /etc/nginx/sites-available/crystal
Example:
server {
listen 80;
listen [::]:80;
server_name YourDomain.com www.YourDomain.com;
# Limit the maximum size of files that can be uploaded via POST requests
client_max_body_size 3M;
location/
{
root /var/www/crystal/frontend/dist;
try_files $uri $uri /index.html;
}
location /api/
{
proxy_pass http://localhost:3000/;
proxy_hide_header X-Powered-By;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
Save changes - 'ctrl + x', 'y', 'Enter', then restart nginx with the command:
systemctl restart nginx
3. Creating a .env.prodDomain file in the frontend part and building the project for the domain.
Change the sample text to the name of your domain and enter the command:
cd /var/www/crystal/frontend && echo VITE_API_BASE_URL=http://YourDomain/api > ./env/.env.prodDomain && npm run build:prod:domain
4. Creating a .env.prodDomain file in the backend part of the project.
Enter the command:
cd /var/www/crystal/backend && nano ./env/.env.prodDomain
Next, enter the data below in the window that opens, and replace the sample text in the variable - 'CORS_ORIGIN', with your domain:
APP_MODE=prod (domain)
CORS_ORIGIN=http://YourDomain
After adding the code, press sequentially - 'ctrl + x', 'y', 'Enter'.
Next, you need to delete the old pm2 process and start a new one, to do this, enter the command:
pm2 kill && npm run start:prod:domain && pm2 save && pm2 startup && pm2 status
If the launch is successful, the process named - 'prodDomain' should have the status - 'online'.
The site will be available at your domain address. The connection should be via the protocol - 'http', check this in the address bar of the browser. The site will not open if the connection is established via the protocol - 'https'.
If you have already installed an SSL certificate on your domain, the browser may automatically redirect the request from the 'http' protocol to 'https'.
To remove the redirect, enter the following line in the address bar of the Chrome browser:
chrome://net-internals/#hsts
Then in the window that opens, in the field - 'Delete domain security policies', enter your domain and click the button - 'Delete'.
Next, you can connect a free Let's Encrypt SSL certificate to the domain, with automatic renewal, for this use this instructions.
Share
BTC (Network BTC) - 1C2EWWeEXVhg93hJA9KovpkSd3Rn3BkcYm
Ethereum (Network ERC20) - 0x05037ecbd8bcd15631d780c95c3799861182e6b8
Comment on