Virtual hosts in Nginx
Go to Nginx configuration files directory
cd /usr/local/etc/nginx
mkdir -p conf.d/
vi nginx.conf
Add following include directive at the end of the file before the closing } tag.
include /etc/nginx/conf.d/*.conf;
Check configuration using command
nginx -t
If there are no errors run following command
service nginx restart
For adding virtual hosts
cd /usr/local/etc/nginx/conf.d/
vi app.example.com.conf
Add following configuration and save the conf file
server {
listen 80;
server_name app.example.com;
root /usr/local/www/app.example.com/;
index index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
Deny access to .htaccess if available
location ~ /.ht {
deny all;
}
}
mkdir -p /usr/local/www/app.example.com/
vi /usr/local/www/app.example.com/index.html
service nginx restart