How can I set up sub-domains in Nginx?
Things I have set-up already"
Nginx running a Ruby rack app
DNS set-up with DigitalOcean
How do I create a sub-domain to root to another ruby app?
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!
Very simple steps
Create a folder “sub.example.com” in /var/www/html/
Create a config file “sub.example.com” in etc/nginx/site-availabe
server {
listen 80;
listen [::]:80;
root /var/www/html/sub.example.com;
index index.php index.html index.htm index.nginx-debian.html;
server_name sub.example.com www.sub.example.com;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME
$document_root/$fastcgi_script_name;
}
}
Note php7.2-fpm may be change by your using php version 3. Run
ln -s /etc/nginx/sites-available/sub.example.com /etc/nginx/sites-enabled/sub.example.com
sudo nginx -tsudo systemctl restart nginx
To do this you would:
1.) Create an A record on your existing domain in the DNS system for your new subdomain and point it to your droplet’s IP.
2.) Create a second (non-default) server {} block in your nginx configuration pointing to your second app.
3.) Restart nginx with the command:
service nginx restart
This comment has been deleted
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.