allanbrey
By:
allanbrey

How to create subdomain with NGINX ?

January 22, 2014 4.6k views
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; } }
2 Answers
The config looks proper to me, you just need to add a DNS record for the subdomain and you should be good to go:

Type: A
Name: teste
Value: your droplet's IP address
- Personally I prefer to make a new .conf file for each subdomain (less problem, less complicated).
- As for your file you mentioned, as far as I know, the root contains only the directory, not file
something like: root /var/www/teste.uberabasites.com;
- Apart of that, all seems ok to me. but it's always a good idea to take a look at the log file.
Have another answer? Share your knowledge.