Guest User

Untitled

a guest
Jul 21st, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. if [ $# -eq 0 ]
  4. then
  5. echo "No arguments supplied"
  6. exit 1
  7. fi
  8.  
  9. domain=$1
  10. root="/home/forge/$domain"
  11. block="/etc/nginx/sites-available/$domain"
  12.  
  13. # Create the Document Root directory
  14. sudo mkdir -p $root
  15.  
  16. # Assign ownership to your regular user account
  17. sudo chown -R $USER:$USER $root
  18.  
  19. # Create the Nginx server block file:
  20. sudo tee $block > /dev/null <<EOF
  21. server {
  22. listen 80;
  23. server_name $domain www.$domain;
  24. root /home/forge/$domain/public;
  25.  
  26. index index.html index.htm index.php;
  27.  
  28. charset utf-8;
  29.  
  30. location / {
  31. try_files \$uri \$uri/ /index.php?\$query_string;
  32. }
  33.  
  34. location = /favicon.ico { access_log off; log_not_found off; }
  35. location = /robots.txt { access_log off; log_not_found off; }
  36.  
  37. access_log off;
  38. error_log /var/log/nginx/$domain-error.log error;
  39.  
  40. sendfile off;
  41.  
  42. client_max_body_size 100m;
  43.  
  44.  
  45. location ~ \.php$ {
  46. fastcgi_split_path_info ^(.+\.php)(/.+)$;
  47. fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
  48. fastcgi_index index.php;
  49. include fastcgi_params;
  50. fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
  51. fastcgi_intercept_errors off;
  52. fastcgi_buffer_size 16k;
  53. fastcgi_buffers 4 16k;
  54. }
  55.  
  56.  
  57. #browser caching of static assets
  58. location ~* \.(jpg|jpeg|png|gif|ico)$ {
  59. expires 7d;
  60. }
  61.  
  62. #browser caching of css and js
  63. location ~* \.(css|js)$ {
  64. expires 7d;
  65. }
  66.  
  67. location ~ /\.ht {
  68. deny all;
  69. }
  70. }
  71.  
  72. EOF
  73.  
  74. # Link to make it available
  75. sudo ln -fs "/etc/nginx/sites-available/$1" "/etc/nginx/sites-enabled/$1"
  76.  
  77. # Test configuration and reload if successful
  78. sudo nginx -t && sudo service nginx reload
Add Comment
Please, Sign In to add comment