Question

How to create subdomain with NGINX ?

  • Posted January 22, 2014

I have my domain uberabasites.com Now, I want to create teste.uberabasites.com

server { server_name uberabasites.com; listen 80; root /var/www/uberabasites.com/public_html; access_log /var/www/uberabasites.com/logs/access.log; error_log /var/www/uberabasites.com/logs/error.log; index index.html index.php; location / { try_files $uri $uri/ @rewrites; } location @rewrites { rewrite ^ /index.php last; } location ~* .(jpg|jpeg|gif|css|png|js|ico|html)$ { access_log off; expires max; } location ~ /.ht { deny all; } location ~ .php { fastcgi_index index.php; fastcgi_split_path_info ^(.+.php)(.*)$; include /etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } }

server { server_name teste.uberabasites.com; listen 80; root /var/www/teste.uberabasites.com/public_html; access_log /var/www/teste.uberabasites.com/logs/access.log; error_log /var/www/teste.uberabasites.com/logs/error.log; index index.html index.php; location / { try_files $uri $uri/ @rewrites; } location @rewrites { rewrite ^ /index.php last; } location ~* .(jpg|jpeg|gif|css|png|js|ico|html)$ { access_log off; expires max; } location ~ /.ht { deny all; } location ~ .php { fastcgi_index index.php; fastcgi_split_path_info ^(.+.php)(.*)$; include /etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } }

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

  • Personally I prefer to make a new .conf file for each subdomain (less problem, less complicated). <br>- As for your file you mentioned, as far as I know, the root contains only the directory, not file <br>something like: root /var/www/teste.uberabasites.com; <br>- Apart of that, all seems ok to me. but it’s always a good idea to take a look at the log file.

The config looks proper to me, you just need to add a DNS record for the subdomain and you should be good to go: <br> <br>Type: A <br>Name: teste <br>Value: your droplet’s IP address