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!
This comment has been deleted
This comment has been deleted
This comment has been deleted
This comment has been deleted
This comment has been deleted
This comment has been deleted
As I often work with multiple domain-names and I like to keep my configs as clean and rock solid as possible I almost always use regex with nginx.
Following redirects any subdomain.domain.tld into domain.tld.
server {
listen 80;
server_name ~^((?<subdomain>.*)\.)(?<domain>[^.]+)\.(?<tld>[^.]+)$;
return 301 $scheme://${domain}.${tld};
}
If you want to redirect a subdomain to a page this is possible as well:
server {
listen 80;
server_name ~^((?<subdomain>.*)\.)(?<domain>[^.]+)\.(?<tld>[^.]+)$;
return 301 $scheme://${domain}.${tld}/${subdomain};
}
Now any subdomain.domain.tld gets redirected to domain.tld/subdomain.
You don’t need a new server block for this task. Just use this if statement in your existing server block.
if ( $http_host ~* "www\.(.*)") {
rewrite ^ http://$1$request_uri permanent;
}
If you are making this server config redirect for a WordPress install make sure to log into the Dashboard -> Settings -> General before you restart nginx.
Modify the WordPress Address (URL) and Site Address (URL) to match the www .example.com or example.com you configured as the default in your nginx config. Make sure you click the [Save Changes] button, then restart nginx. Do it in this order. Otherwise, you will find your server in an endless redirect loop.
Everythings seems ok but when I access home I see 404 page. And If I use the .htaccess from ubuntu the example.com is redirected to example.com/index.php I don’t want these index.php
HTTP/1.1 301 Moved Permanently … Content-Type: text/html Content-Length: 193 Connection: keep-alive Location: http://www.example.com/
server { listen 80;
root /var/www/html/example;
index index.php index.html index.htm;
server_name example.com; return 301 $scheme://www.example.com$request_uri; # error_page 401 403 404 /404.html;
location / {
try_files $uri $uri/ @proxy;
}
location @proxy {
proxy_pass http://127.0.0.1:8080;
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;
}
location ~ \.php$ {
proxy_pass http://127.0.0.1:8080;
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;
}
location ~ /\. {
deny all;
}
location ~* .(jpg|jpeg|png|gif|ico|css|js|swf)$ {
expires 365d;
}
}