Guest User

Untitled

a guest
Dec 10th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.14 KB | None | 0 0
  1. # Server Commissioning
  2.  
  3. Ubuntu mainstream packages are pretty out of date for nginx; we want version > 1.0, so we need to reference repository that has more recent versions before we install:
  4.  
  5. $ add-apt-repository ppa:nginx/stable && apt-get update
  6.  
  7. Update, upgrade and install nginx and development tools:
  8.  
  9. $ apt-get -y install nginx git-core build-essential
  10.  
  11. Extras for RubyGems and Rails:
  12.  
  13. $ apt-get -y install zlib1g-dev
  14. $ apt-get -y install libssl-dev libsqlite3-dev
  15. $ apt-get -y install libreadline5-dev
  16. $ apt-get -y install curl
  17.  
  18. Add a deployment user:
  19.  
  20. $ useradd -m -g staff -s /bin/bash deployer
  21. $ passwd deployer
  22.  
  23. Create a custom shudders file, and add the following line (sudo vi /etc/sudoers.d/our-company):
  24.  
  25. %staff ALL=(ALL) ALL
  26.  
  27. ### Nginx
  28. Edit /etc/nginx/proxy_params and add shared proxy config settings (optional)
  29.  
  30. ```
  31. proxy_set_header Host $host;
  32.  
  33. # needed to forward user's IP address to application server
  34. proxy_set_header X-Real-IP $remote_addr;
  35.  
  36. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  37. proxy_set_header X-Forwarded-Proto $scheme;
  38.  
  39. proxy_send_timeout 90;
  40. proxy_read_timeout 90;
  41.  
  42. proxy_buffer_size 4k;
  43. proxy_buffers 4 32k;
  44. proxy_busy_buffers_size 64k;
  45. proxy_temp_file_write_size 64k;
  46. ```
  47.  
  48.  
  49.  
  50.  
  51. # Ruby & Rails Setup ror each User / App
  52.  
  53. $ sudo adduser --shell /bin/bash example-user
  54. $ su - example-user
  55. $ cd ~example-user
  56.  
  57. ### Install rbenv:
  58.  
  59. Check out rbenv into ~/.rbenv :
  60.  
  61. 
$ git clone git://github.com/sstephenson/rbenv.git .rbenv
  62.  
  63. Add ~/.rbenv/bin to your $PATH for access to the rbenv command-line
:
  64.  
  65. $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> 
$ ~/.bash_profile
  66.  
  67. Add rbenv init to your shell to enable shims and autocompletion:
  68.  
  69. 
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
  70.  
  71. Restart your shell so the path changes take effect in order to use rbenv:
  72.  
  73. 
$ exec $SHELL
  74.  
  75. If the above shell reload doesn't give you the rbenv command, then you will have to exit and re-enter the shell
  76.  
  77. Use rbenv to install a specific Ruby version
:
  78.  
  79. $ rbenv install 1.9.2-p290
  80.  
  81. Rebuild the shim binaries. You should do this any time you install a new Ruby binary e.g. when installing a new Ruby version, or when installing a gem that provides a binary:
  82.  
  83. $ rbenv rehash
  84.  
  85. Set a global Ruby version for all shells:
  86.  
  87. $ rbenv global 1.9.2-p290
  88.  
  89. ### Unicorn
  90.  
  91. $ gem install bundler unicorn --no-rdoc --no-ri; rbenv rehash
  92.  
  93. Add the following environment config variables to a file at `/etc/unicorn/example.co.uk.conf` (The Unicorn process will look here):
  94.  
  95. RAILS_ROOT=/home/example.co.uk/website
  96. RAILS_ENV=production
  97.  
  98. Clone your app into ~/website (depends upon if you are using git, or some other source), and then install your bundle:
  99.  
  100. $ cd ~/website
  101. $ bundle install
  102.  
  103. create app-specific unicorn init file here and make it executable (See init file in this gist):
  104.  
  105. $ sudo chmod +x /etc/init.d/unicorn_example.co.uk
  106.  
  107. Add a unicorn.rb app config file to your Rails app at `config/unicorn.rb` (Example attached). Edit the file to match the directory path to your app, and user names and groups. Also uncomment the 'listen' directive in the file for listening on a TCP port.
  108.  
  109. Check that unicorn can be started:
  110.  
  111. $ /etc/init.d/unicorn_example.co.uk start
  112.  
  113. Check that unicorn is listening on the configured port (8080 in this example):
  114.  
  115. $ netstat -natp | grep unicorn
  116.  
  117. You should see something like:
  118.  
  119. Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
  120. tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 5272/unicorn.rb -E
  121.  
  122. Okay, if that's all good, then you can comment out the TCP port listening directive in `config/unicorn.rb`, so that unicorn worker processes are only accessible to Nginx via Unix socket.
  123.  
  124. ### Nginx virtual hosts
  125. Create an Nginx virtual hosts configuration file in 'sites-available' and enter contents of nginx_virtual_host file:
  126.  
  127. $ sudo vi /etc/nginx/sites-available/example.co.uk
  128.  
  129. Create a symlink from sites-available to site-enabled:
  130.  
  131. $ sudo ln -s /etc/nginx/sites-available/example.co.uk /etc/nginx/sites-enabled/example.co.uk
Add Comment
Please, Sign In to add comment