By sarunw
I have Rails website where I want to enable my users to choose their custom domain and point to my website.
I search and I found that I can declare catch app server block
server { server_name _; }
Is this the right way to do support dynamic custom domain? Anything I should concern regarding security, performance, etc.
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!
Hello,
In case I’ve understood it corretly, yes, you can use the catch-all server block to support dynamic custom domains in Nginx. The catch-all server block, represented by an underscore (_) in the server_name directive, will handle all requests that do not match any other server block. Here’s an example:
server {
listen 80 default_server;
server_name _;
root /path/to/your/rails/public;
index index.html;
location / {
proxy_pass http://your_rails_app_server;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# Additional configuration related to your Rails app
}
Replace /path/to/your/rails/public with the correct path to your Rails application’s public folder and http://your_rails_app_server with the URL of your Rails application server (for example, a Puma or Unicorn server).
However, there are a few things to consider when using this approach:
Security: Allowing users to point their custom domains to your website might expose your website to security risks, as attackers could set up a phishing website using a custom domain that points to your server. To mitigate such risks, you should implement proper validation and verification procedures when allowing users to add custom domains.
SSL/TLS Certificates: If you want to enable HTTPS for your users’ custom domains, you will need to configure SSL/TLS certificates for each domain. One way to do this is to use a wildcard certificate from a certificate authority like Let’s Encrypt. Alternatively, you can use a service like Cloudflare, which provides SSL/TLS for custom domains.
Performance: If you expect a large number of custom domains, you might need to adjust your Nginx worker connections and worker processes settings to handle the increased traffic.
Application-level handling: Your Rails application should be able to identify the custom domain from the incoming request and serve the appropriate content. This can be done by inspecting the Host header in the request and mapping it to the user or content in your application.
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.