laravel-react.sh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/bin/bash
  2. set -e
  3. if [ "$#" -ne 1 ]
  4. then
  5. echo "USAGE: $0 DOMAIN"
  6. exit 1
  7. fi
  8. echo "check $1.conf"
  9. if [ ! -d /var/www/$1/logs ]
  10. then
  11. mkdir -p /var/www/$1/logs
  12. chown -R www-data:www-data /var/www/$1/logs
  13. fi
  14. if [ ! -f /etc/nginx/sites-enabled/$1.conf ]
  15. then
  16. # https://laravel.com/docs/10.x/deployment
  17. cat > /etc/nginx/sites-enabled/$1.conf <<EOF
  18. server {
  19. server_name $1;
  20. root /var/www/$1/htdocs/public;
  21. access_log /var/www/$1/logs/access.log;
  22. error_log /var/www/$1/logs/error.log;
  23. add_header X-Frame-Options "SAMEORIGIN";
  24. add_header X-Content-Type-Options "nosniff";
  25. index index.php;
  26. charset utf-8;
  27. gzip on;
  28. gzip_comp_level 9;
  29. gzip_min_length 1k;
  30. gzip_types text/plain text/css application/xml application/javascript;
  31. gzip_vary on;
  32. client_max_body_size 128M;
  33. location /pcd/ {
  34. alias /var/www/$1/dashboard/;
  35. try_files \$uri \$uri/ /pcd/index.html;
  36. location ~* \\.(css|js|png|jpg|jpeg|gif|gz|svg|mp4|ogg|ogv|webm|htc|xml|woff)\$ {
  37. access_log off;
  38. expires max;
  39. }
  40. }
  41. location / {
  42. try_files \$uri \$uri/ /index.php?\$query_string;
  43. }
  44. location = /favicon.ico { access_log off; log_not_found off; }
  45. location = /robots.txt { access_log off; log_not_found off; }
  46. error_page 404 /index.php;
  47. location ~ \.php\$ {
  48. fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
  49. fastcgi_param SCRIPT_FILENAME \$realpath_root\$fastcgi_script_name;
  50. include fastcgi_params;
  51. }
  52. location ~ /\.(?!well-known).* {
  53. deny all;
  54. }
  55. }
  56. EOF
  57. chmod 644 /etc/nginx/sites-enabled/$1.conf
  58. fi
  59. echo "done($1)."
  60. exit 0