Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we use nginx for both wordpress and drupal?

I have a debian machine on which I installed nginx for my web server worker process. But we just need to change a little for wordpress in default nginx configuration which is located /etc/nginx/sites-enabled/ !

/etc/nginx/sites-enabled/wordpress.com
/etc/nginx/sites-enabled/drupal.com

Can I know sample nginx configurations for those two websites under single debian machine.

like image 459
Tin Aung Lin Avatar asked Dec 11 '25 09:12

Tin Aung Lin


1 Answers

You can run multiple sites using nginx, analogous to an apache vhost.

In /etc/nginx/sites-enabled, you can add two vhosts

wordpress.example.com

server {
       listen 80;
       server_name wordpress.example.com;
       root /var/www/wordpress;
#      if ($http_host != "www.example.com") {
#                rewrite ^ http://www.example.com$request_uri permanent;
#      }
       index index.php index.html;
       location = /favicon.ico {
                log_not_found off;
                access_log off;
       }
       location = /robots.txt {
                allow all;
                log_not_found off;
                access_log off;
       }
       # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
       location ~ /\. {
                deny all;
                access_log off;
                log_not_found off;
       }
       location / {
                try_files $uri $uri/ /index.php?$args;
       }
       # Add trailing slash to */wp-admin requests.
       rewrite /wp-admin$ $scheme://$host$uri/ permanent;
       location ~*  \.(jpg|jpeg|png|gif|css|js|ico)$ {
                expires max;
                log_not_found off;
       }
       location ~ \.php$ {
                try_files $uri =404;
                include /etc/nginx/fastcgi_params;
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
       }
}

and

drupal.example.com

server {
       listen 80;
       server_name drupal.example.com;
       root /var/www/drupal;
#      if ($http_host != "www.example.com") {
#                rewrite ^ http://www.example.com$request_uri permanent;
#      }
       index index.php index.html;
       location = /favicon.ico {
                log_not_found off;
                access_log off;
       }
       location = /robots.txt {
                allow all;
                log_not_found off;
                access_log off;
       }
       # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
       location ~ /\. {
                deny all;
                access_log off;
                log_not_found off;
       }
       location / {
                try_files $uri $uri/ /index.php?$args;
       }
       # Add trailing slash to */wp-admin requests.
       rewrite /wp-admin$ $scheme://$host$uri/ permanent;
       location ~*  \.(jpg|jpeg|png|gif|css|js|ico)$ {
                expires max;
                log_not_found off;
       }
       location ~ \.php$ {
                try_files $uri =404;
                include /etc/nginx/fastcgi_params;
                fastcgi_pass 127.0.0.1:9001;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
       }
}
like image 75
Nick Avatar answered Dec 14 '25 08:12

Nick



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!