{"id":6215,"date":"2015-04-15T21:02:58","date_gmt":"2015-04-15T13:02:58","guid":{"rendered":"https:\/\/webhostinggeeks.com\/howto\/?p=6215"},"modified":"2023-06-23T13:12:54","modified_gmt":"2023-06-23T13:12:54","slug":"multiple-wordpress-sites-on-nginx","status":"publish","type":"post","link":"https:\/\/webhostinggeeks.com\/howto\/multiple-wordpress-sites-on-nginx\/","title":{"rendered":"How to Setup Multiple WordPress Sites on Nginx"},"content":{"rendered":"<p>This article describes how to install and configure multiple WordPress\u00a0sites on Nginx and the steps have been prepared based on CentOS 7.0 and Nginx 1.6.3. NGINX (pronounced Engine ex) is an open source high performance web servers and able to handle large number of concurrent connections. It has the lowest memory footprint if compared to the alternate web server, apache http server. Please follow the following steps to host multiple WordPress sites on Nginx. Please note that this configuration also tested working on RHEL 7 and Oracle Linux 7.<\/p>\n<h4>Steps to Setup Multiple WordPress Sites on Nginx<\/h4>\n<p>1. First, we need to set up directories for multi-sites the server blocks and additional WordPress configuration files :<\/p>\n<pre># mkdir -p \/etc\/nginx\/conf.d\n# mkdir -p \/etc\/nginx\/sites-available\n<\/pre>\n<p>2. Tell the main nginx.conf file to look for the new setup directories :<\/p>\n<pre># vi \/etc\/nginx\/nginx.conf\n<\/pre>\n<p>Add the following into the configuration file :<\/p>\n<pre>    include \/etc\/nginx\/conf.d\/*.conf;\n    include \/etc\/nginx\/sites-available\/*.conf;\n<\/pre>\n<pre>user  nginx;\nworker_processes  2;\n\nerror_log  \/var\/log\/nginx\/error.log warn;\npid        \/var\/run\/nginx.pid;\n\n\nevents {\n    worker_connections  1024;\n}\n\n\nhttp {\n    include       \/etc\/nginx\/mime.types;\n    default_type  application\/octet-stream;\n\n    log_format  main  '$remote_addr - $remote_user [$time_local] \"$request\" '\n                      '$status $body_bytes_sent \"$http_referer\" '\n                      '\"$http_user_agent\" \"$http_x_forwarded_for\"';\n\n    access_log  \/var\/log\/nginx\/access.log  main;\n\n\n    include \/etc\/nginx\/conf.d\/*.conf;\n    include \/etc\/nginx\/sites-available\/*.conf;\n}\n<\/pre>\n<p>3. Add new wordpress configuration file :<\/p>\n<pre># vi \/etc\/nginx\/conf.d\/wordpress.conf\n<\/pre>\n<pre># WORDPRESS : Rewrite rules, sends everything through index.php and keeps the appended query string intact\nlocation \/ {\n    try_files $uri $uri\/ \/index.php?q=$uri&amp;$args;\n}\n\n# SECURITY : Deny all attempts to access PHP Files in the uploads directory\nlocation ~* \/(?:uploads|files)\/.*\\.php$ {\n    deny all;\n}\n# REQUIREMENTS : Enable PHP Support\nlocation ~ \\.php$ {\n    # SECURITY : Zero day Exploit Protection\n    try_files $uri =404;\n    # ENABLE : Enable PHP, listen fpm sock\n    fastcgi_split_path_info ^(.+\\.php)(\/.+)$;\n    fastcgi_pass   127.0.0.1:9000;\n    fastcgi_index index.php;\n    fastcgi_send_timeout 300s;\n    fastcgi_read_timeout 300s;\n    include fastcgi_params;\n    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\n    fastcgi_buffer_size 128k;\n    fastcgi_buffers 256 4k;\n    fastcgi_busy_buffers_size 256k;\n    fastcgi_temp_file_write_size 256k;\n    fastcgi_intercept_errors on;\n}\n# PLUGINS : Enable Rewrite Rules for SiteMap\nrewrite ^\/sitemap(-+([a-zA-Z0-9_-]+))?\\.xml$ \"\/index.php?xml_sitemap=params=$2\" last;\nrewrite ^\/sitemap(-+([a-zA-Z0-9_-]+))?\\.xml\\.gz$ \"\/index.php?xml_sitemap=params=$2;zip=true\" last;\nrewrite ^\/sitemap(-+([a-zA-Z0-9_-]+))?\\.html$ \"\/index.php?xml_sitemap=params=$2;html=true\" last;\nrewrite ^\/sitemap(-+([a-zA-Z0-9_-]+))?\\.html.gz$ \"\/index.php?xml_sitemap=params=$2;html=true;zip=true\" last;\n<\/pre>\n<p>4. Add new common configuration file :<\/p>\n<pre># vi \/etc\/nginx\/conf.d\/common.conf\n<\/pre>\n<pre># Global configuration file.\n# ESSENTIAL : Configure Nginx Listening Port\n\nlisten 80;\n# ESSENTIAL : Default file to serve. If the first file isn't found,\nindex index.php index.html index.htm;\n# ESSENTIAL : no favicon logs\nlocation = \/favicon.ico {\n    log_not_found off;\n    access_log off;\n}\n# ESSENTIAL : robots.txt\nlocation = \/robots.txt {\n    allow all;\n    log_not_found off;\n    access_log off;\n}\n# ESSENTIAL : Configure 404 Pages\nerror_page 404 \/404.html;\n# ESSENTIAL : Configure 50x Pages\nerror_page 500 502 503 504 \/50x.html;\n    location = \/50x.html {\n        root \/usr\/share\/nginx\/html;\n    }\n# SECURITY : Deny all attempts to access hidden files .abcde\nlocation ~ \/\\. {\n    deny all;\n}\n# PERFORMANCE : Set expires headers for static files and turn off logging.\nlocation ~* ^.+\\.(js|css|swf|xml|txt|ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {\n    access_log off; log_not_found off; expires 30d;\n   #    expires max;\n   add_header Pragma no-cache;\n   add_header Cache-Control \"public\";\n}\n<\/pre>\n<p>5. Create the document root for mutiple websites :<\/p>\n<pre># mkdir -p \/var\/www\/html\/example-site1\n# mkdir -p \/var\/www\/html\/example-site2\n<\/pre>\n<p>6. Add the server block configuration for example-site1.com :<\/p>\n<pre># vi \/etc\/nginx\/sites-available\/example-site1.com.conf\n<\/pre>\n<p>Add lines as below :<\/p>\n<pre>server {\n    listen     80;\n    server_name example-site1.com;\n    rewrite ^\/(.*)$ http:\/\/www.example-site1.com\/$1 permanent;\n}\n\nserver {\n        server_name www.example-site1.com;\n        root \/var\/www\/html\/example-site1;\n        access_log \/var\/log\/nginx\/example-site1.com.access.log;\n        error_log \/var\/log\/nginx\/example-site1.com.error.log;\n        include conf.d\/common.conf;\n        include conf.d\/wordpress.conf;\n}\n<\/pre>\n<p>7. Add the server block configuration for example-site2.com :<\/p>\n<pre># vi \/etc\/nginx\/sites-available\/example-site2.com.conf\n<\/pre>\n<p>Add lines as below :<\/p>\n<pre>server {\n    listen     80;\n    server_name example-site2.com;\n    rewrite ^\/(.*)$ http:\/\/www.example-site2.com\/$1 permanent;\n}\n\nserver {\n        server_name www.example-site2.com;\n        root \/var\/www\/html\/example-site2;\n        access_log \/var\/log\/nginx\/example-site2.com.access.log;\n        error_log \/var\/log\/nginx\/example-site2.com.error.log;\n        include conf.d\/common.conf;\n        include conf.d\/wordpress.conf;\n}\n<\/pre>\n<p>8. Check the nginx syntax :<\/p>\n<pre># sudo nginx -t\nnginx: the configuration file \/etc\/nginx\/nginx.conf syntax is ok\nnginx: configuration file \/etc\/nginx\/nginx.conf test is successful\n<\/pre>\n<p>9. Restart Nginx service to apply for\u00a0Multiple WordPress sites on Nginx configuration :<\/p>\n<pre># sudo systemctl restart  nginx.service\n<\/pre>\n<p><img decoding=\"async\" class=\"alignnone wp-image-6007 size-full lazyload\" data-src=\"https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2015\/02\/nginx-ehowstuff.png\" alt=\"Multiple WordPress sites on Nginx\" width=\"600\" height=\"349\" data-srcset=\"https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2015\/02\/nginx-ehowstuff.png 600w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2015\/02\/nginx-ehowstuff-300x175.png 300w\" data-sizes=\"(max-width: 600px) 100vw, 600px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 600px; --smush-placeholder-aspect-ratio: 600\/349;\" \/><\/p>\n<p><a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-configure-single-and-multiple-wordpress-site-settings-with-nginx\" target=\"_blank\" rel=\"noopener\">Resource<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article describes how to install and configure multiple WordPress\u00a0sites on Nginx and the steps have been prepared based on CentOS 7.0 and Nginx 1.6.3. NGINX (pronounced Engine ex) is&#8230;<\/p>\n","protected":false},"author":6,"featured_media":6240,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"wds_primary_category":0,"footnotes":""},"categories":[2055,2056,1014],"tags":[1933],"class_list":["post-6215","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-centos","category-cms","category-nginx","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/6215","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/comments?post=6215"}],"version-history":[{"count":0,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/6215\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media\/6240"}],"wp:attachment":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media?parent=6215"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/categories?post=6215"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/tags?post=6215"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}