webserver.sh 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!\bin\bash
  2. echo -n "Nama Domain : "
  3. read domain
  4. echo -n "Alamat Email : "
  5. read email
  6. echo -n "V2Ray Port : "
  7. read port
  8. # use the new config
  9. read -r -d '' conf <<"EOT"
  10. server {
  11. listen 85;
  12. listen [::]:85;
  13. # SSL configuration
  14. #
  15. listen 80 ssl default_server;
  16. listen [::]:80 ssl default_server;
  17. ssl on;
  18. ssl_certificate /etc/letsencrypt/live/v_domain/fullchain.pem;
  19. ssl_certificate_key /etc/letsencrypt/live/v_domain/privkey.pem;
  20. ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  21. ssl_ciphers HIGH:!aNULL:!MD5;
  22. #
  23. # Note: You should disable gzip for SSL traffic.
  24. # See: https://bugs.debian.org/773332
  25. #
  26. # Read up on ssl_ciphers to ensure a secure configuration.
  27. # See: https://bugs.debian.org/765782
  28. #
  29. # Self signed certs generated by the ssl-cert package
  30. # Don't use them in a production server!
  31. #
  32. # include snippets/snakeoil.conf;
  33. root /var/www/html;
  34. # Add index.php to the list if you are using PHP
  35. index index.html index.htm index.nginx-debian.html;
  36. server_name v_domain;
  37. location / {
  38. # First attempt to serve request as file, then
  39. # as directory, then fall back to displaying a 404.
  40. try_files $uri $uri/ =404;
  41. }
  42. location /ray { # Consistent with the path of V2Ray configuration
  43. if ($http_upgrade != "websocket") { # Return 404 error when WebSocket upgrading negotiate failed
  44. return 404;
  45. }
  46. proxy_redirect off;
  47. proxy_pass http://127.0.0.1:v_port; # Assume WebSocket is listening at localhost on port of 10000
  48. proxy_http_version 1.1;
  49. proxy_set_header Upgrade $http_upgrade;
  50. proxy_set_header Connection "upgrade";
  51. proxy_set_header Host $host;
  52. # Show real IP in v2ray access.log
  53. proxy_set_header X-Real-IP $remote_addr;
  54. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  55. }
  56. }
  57. EOT
  58. # installing
  59. apt install software-properties-common -y
  60. apt install certbot -y
  61. # creating SSL Certificates
  62. certbot certonly --standalone --preferred-challenges http --agree-tos --email $email -d $domain --agree-tos
  63. certbot renew --force-renewal
  64. apt install nginx -y
  65. # update config
  66. cd /etc/nginx/sites-available
  67. mv default ~/default-nginx.conf
  68. echo "$conf" > default
  69. sed -i "s/v_domain/$domain/g" default
  70. sed -i "s/v_port/$port/g" default
  71. systemctl restart nginx