Hi there!
I have successfully deployed a doplet using ubuntu + rails + nginx + unicorn. Everything is up and running.
Ideally I would like app.mydomain.com to run my ruby application and mydomain.com to serve static html content. Is that something that’s possible with nginx?
Thanks! Alex
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
That’s definitely possible. You’ll just need to define a new server block in your Nginx configuration, pointing to the directory holding the static files. You also need to set server_name for each block so Nginx knows how to direct the requests.
Here’s an example:
- upstream app_server { server 127.0.0.1:8080 fail_timeout=0; }
-
- server {
- listen 80;
- root /home/rails/public;
- server_name app.mydomain.com;
- index index.htm index.html;
-
- location / {
- try_files $uri/index.html $uri.html $uri @app;
- }
-
- location ~* ^.+\.(jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|mp3|flv|mpeg|avi)$ {
- try_files $uri @app;
- }
-
- location @app {
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- proxy_set_header Host $http_host;
- proxy_redirect off;
- proxy_pass http://app_server;
- }
- }
-
- server {
- listen 80;
- root /var/www/html;
- server_name mydomain.com;
- index index.htm index.html;
-
- location / {
- try_files $uri $uri/ =404;
- }
-
- error_page 404 /404.html;
- error_page 500 502 503 504 /50x.html;
- location = /50x.html {
- root /usr/share/nginx/html;
- }
- }
For more information, check out these tutorials:
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.