Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

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!
Great tutorial!
But doesn’t a simple
| Record Type | Source | Target |
|---|---|---|
| A | domain.com | ip_address |
| CNAME | www.domain.com | domain.com |
do the trick?
Still Unable to redirect to WWW URL Created two A records
Waiting for your quick reply…
You should use:
server {
server_name www.domain.com;
return 301 $scheme://domain.com$request_uri;
}
server {
server_name domain.com;
[...]
}
Otherwise you will get HTTP/1.1 301 Moved Permanently for the www and non-www versions.
Using the code above you’ll get HTTP/1.1 200 OK for the non-www domain.
See: http://wiki.nginx.org/Pitfalls#Server_Name
Thanks for the tutorial, but I don’t understand how I achieve it working without the nginx configuration:
server {
server_name www.example.com;
return 301 $scheme://example.com$request_uri;
}
I did the nginx configuration as you say, and didn’t worked, in browsers could read “To many redirections”, after some tries, I delete the redirecting block of nginx configuracion and it worked !!
Why?
I think my registar already made a redirection of www to non www… but then, It shouldn’t be necessary the first part of this tutorial, isn’t it?
Thans a lot for your explanations
When I test the config file /sites-enabled/default I get the following error:
[emerg] “server” directive is not allowed here in /etc/nginx/sites-enabled/default:20
This is after a fresh droplet install.
This comment has been deleted
when i run : curl -I http://example.com
it show : curl: (7) Failed to connect to xxx.com port 80: Connection timed out
One question. I’m using the DO rails droplet (Nginx and Ubuntu). The thing is that the config file for nginx, named rails, is already populated with some data. What should i keep/delete in order for this to work?
upstream app_server { server unix:/var/run/unicorn.sock fail_timeout=0; }
server { listen 80; root /home/rails/joumi/public; server_name _; 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;
}
}
Thanks!
Hmm, it didn’t work for me. I arrive to the “Welcome to nginx” page when browsing to “myotherdomain.com”
server {
server_name www.myotherdomain.com;
return 301 $scheme://test.domain.com$request_uri;
}
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
root /var/www/html;
index index.php index.html index.htm;
#Password protects the test subdomain
auth_basic "Restricted Content";
auth_basic_user_file /etc/nginx/.htpasswd;
# Make site accessible from https://test.domain.com/
server_name test.domain.com;
include snippets/ssl-test.domain.com.conf;
include snippets/ssl-params.conf;
location ~ /.well-known {
allow all;
}
location / {
try_files $uri $uri/ /index.php$is_args$query_string;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
# Mitigate https://httpoxy.org/ vulnerabilities
fastcgi_param HTTP_PROXY "";
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
include fastcgi_params;
}
location ~ \.php$ {
#match actual filename with extension or file not found
#try_files $uri $uri =404;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
}