Last active
September 11, 2024 20:37
-
-
Save suhailroushan13/290d72ecff0971e103bb94e705cbcf93 to your computer and use it in GitHub Desktop.
Sever Block Nginx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1.sudo su | |
2.cd /etc/nginx/sites-enabled/ | |
3.rm -rf * | |
4.cd .. | |
5.cd /etc/nginx/sites-available | |
6.touch domain-name | |
7.Copy paste this block | |
//////////////////////////// From Below Copy | |
server { | |
listen 80; | |
listen [::]:80; | |
server_name tasky.tech www.tasky.tech; | |
location / { | |
proxy_pass http://localhost:3000; | |
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; | |
} | |
} | |
////////////////////////////////// | |
Add domain name in server_name | |
Add port number in localhost | |
type this command | |
sudo ln -s /etc/nginx/sites-available/domain_name /etc/nginx/sites-enabled | |
8.sudo nginx -t // verify everything is ok and successfull | |
9.sudo systemctl restart nginx | |
// Make sure you add A Record in your domain DNS | |
A Record in your domain DNS for www.tasky.tech and tasky.tech | |
10.sudo certbot --nginx | |
11.Type 1,2 or 3,4 or 2 select your domain | |
12.sudo systemctl restart nginx | |
// Without Node Server | |
1.Create a folder name in var/www/domain.com/html/ | |
server { | |
listen 80; | |
listen [::]:80; | |
root /var/www/domain.com/html/ | |
server_name tasky.tech www.tasky.tech; | |
location / { | |
proxy_pass http://localhost:3000; | |
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; | |
} | |
} | |
-------------------------------------------------------------------- | |
#!/bin/bash | |
# Prompt for the filename with a default value | |
default_filename="ketomotors" | |
echo "Enter the filename (default: $default_filename):" | |
read filename | |
# Use default value if no input is provided | |
filename=${filename:-$default_filename} | |
# Switch to root user | |
sudo su | |
# Navigate to /etc/nginx/sites-enabled and remove all files | |
cd /etc/nginx/sites-enabled/ || { echo "Failed to navigate to /etc/nginx/sites-enabled"; exit 1; } | |
sudo rm -rf * | |
# Navigate to /etc/nginx/sites-available | |
cd /etc/nginx/sites-available || { echo "Failed to navigate to /etc/nginx/sites-available"; exit 1; } | |
# Create the file | |
sudo touch "$filename" | |
# Create a symbolic link from sites-available to sites-enabled | |
sudo ln -s /etc/nginx/sites-available/"$filename" /etc/nginx/sites-enabled/ | |
# Test the Nginx configuration | |
sudo nginx -t | |
# If Nginx configuration test is successful, restart Nginx | |
if [ $? -eq 0 ]; then | |
echo "Nginx configuration is successful. Restarting Nginx..." | |
sudo systemctl restart nginx | |
else | |
echo "Nginx configuration test failed. Please check your configuration." | |
fi | |
------------------------------------------------------------------------ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment