server {\r\n server_name www.domain1.com domain1.com;\r\n listen 80;\r\n root \/var\/www\/html\/domain1.com;\r\n access_log \/var\/log\/nginx\/domain1.com-access.log;\r\n error_log \/var\/log\/nginx\/domain1.com-error.log;\r\n index index.php;\r\n \r\n location \/ {\r\n try_files $uri $uri\/ \/index.php?$args;\r\n }\r\n\r\n location ~* \\.(jpg|jpeg|gif|css|png|js|ico|html)$ {\r\n access_log off;\r\n expires max;\r\n }\r\n\r\n location ~ \\.php$ {\r\n try_files $uri = 404;\r\n fastcgi_split_path_info ^(.+\\.php)(\/.+)$;\r\n fastcgi_pass 127.0.0.1:9000;\r\n fastcgi_index index.php;\r\n include \/etc\/nginx\/fastcgi_params;\r\n fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\r\n }\r\n\r\n location ~ \/\\.ht {\r\n deny all;\r\n }\r\n\r\n}<\/pre>\nIf you need to host more than one website on the same server (using the same IP address), you can create a new server block. It is best to create a new configuration file for each website.<\/p>\n
For example, create a second nginx configuration file named \/etc\/nginx\/conf.d\/domain2.com.conf and add the same content as \/etc\/nginx\/conf.d\/domain1.com.conf , but make sure to replace domain1.com with the second domain name including the document root of your website, location of log files etc.:<\/p>\n
server {\r\n server_name www.domain2.com domain2.com;\r\n listen 80;\r\n root \/var\/www\/html\/domain2.com;\r\n access_log \/var\/log\/nginx\/domain2.com-access.log;\r\n error_log \/var\/log\/nginx\/domain2.com-error.log;\r\n index index.php;\r\n \r\n location \/ {\r\n try_files $uri $uri\/ \/index.php?$args;\r\n }\r\n\r\n location ~* \\.(jpg|jpeg|gif|css|png|js|ico|html)$ {\r\n access_log off;\r\n expires max;\r\n }\r\n\r\n location ~ \\.php$ {\r\n try_files $uri = 404;\r\n fastcgi_split_path_info ^(.+\\.php)(\/.+)$;\r\n fastcgi_pass 127.0.0.1:9000;\r\n fastcgi_index index.php;\r\n include \/etc\/nginx\/fastcgi_params;\r\n fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\r\n }\r\n\r\n location ~ \/\\.ht {\r\n deny all;\r\n }\r\n\r\n}<\/pre>\nIf you use Ubuntu OS, create the ‘domain1.com.conf’ nginx configuration file to the \/etc\/nginx\/sites-available directory.<\/p>\n
vi \/etc\/nginx\/sites-enabled\/domain1.com.conf<\/pre>\n(add the same content as the content listed above, i.e. \/etc\/nginx\/conf.d\/domain1.com.conf on a CentOS server).<\/p>\n
Then, create a symbolic link from this file to the sites-enabled directory:<\/p>\n
ln -s \/etc\/nginx\/sites-available\/example.com \/etc\/nginx\/sites-enabled\/<\/pre>\nRepeat the same procedure and create new configuration files for all other websites hosted on the server.<\/p>\n