You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

nginx.lin.sh 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/bin/bash
  2. # Update package list and install required packages
  3. echo "Updating package list..."
  4. sudo apt update -y
  5. # Install Nginx
  6. echo "Installing Nginx..."
  7. sudo apt install -y nginx
  8. # Install OpenSSL to generate self-signed certificates
  9. echo "Installing OpenSSL..."
  10. sudo apt install -y openssl
  11. # Create directory to store SSL certificates
  12. echo "Creating SSL directories..."
  13. sudo mkdir -p /etc/ssl/certs
  14. sudo mkdir -p /etc/ssl/private
  15. # Generate the private key and self-signed certificate
  16. echo "Generating self-signed certificate..."
  17. sudo openssl req -x509 -newkey rsa:4096 -keyout /etc/ssl/private/selfsigned.key -out /etc/ssl/certs/selfsigned.crt -days 365 -nodes
  18. # Create Nginx configuration for Gitea with SSL
  19. echo "Creating Nginx configuration for Gitea with SSL..."
  20. cat <<EOF | sudo tee /etc/nginx/sites-available/gitea
  21. server {
  22. listen 80;
  23. server_name ec2-13-201-225-130.ap-south-1.compute.amazonaws.com;
  24. # Redirect HTTP to HTTPS
  25. return 301 https://\$host\$request_uri;
  26. }
  27. server {
  28. listen 443 ssl;
  29. server_name ec2-13-201-225-130.ap-south-1.compute.amazonaws.com;
  30. # Self-signed certificate
  31. ssl_certificate /etc/ssl/certs/selfsigned.crt;
  32. ssl_certificate_key /etc/ssl/private/selfsigned.key;
  33. ssl_protocols TLSv1.2 TLSv1.3;
  34. ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5';
  35. ssl_prefer_server_ciphers on;
  36. location /git/ {
  37. proxy_pass http://127.0.0.1:3000/;
  38. proxy_set_header Host \$host;
  39. proxy_set_header X-Real-IP \$remote_addr;
  40. proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
  41. proxy_set_header X-Forwarded-Proto \$scheme;
  42. proxy_redirect off;
  43. }
  44. }
  45. EOF
  46. # Enable the Nginx configuration
  47. echo "Enabling Nginx configuration..."
  48. sudo ln -s /etc/nginx/sites-available/gitea /etc/nginx/sites-enabled/
  49. # Test Nginx configuration
  50. echo "Testing Nginx configuration..."
  51. sudo nginx -t
  52. # Restart Nginx to apply changes
  53. echo "Restarting Nginx..."
  54. sudo systemctl restart nginx
  55. # Final message
  56. echo "Nginx with self-signed SSL is installed and configured. Your site should now be accessible over HTTPS at https://ec2-13-201-225-130.ap-south-1.compute.amazonaws.com/git"