wordpress - 我们可以将 nginx 同时用于 WordPress 和 Drupal 吗?

标签 wordpress drupal configuration nginx debian

我有一台 debian 机器,在上面为我的 Web 服务器工作进程安装了 nginx。但我们只需要在默认的 nginx 配置中对 wordpress 进行一些更改,该配置位于 /etc/nginx/sites-enabled/ !

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

我可以知道单个 debian 机器下这两个网站的 nginx 配置示例吗?

最佳答案

您可以使用 nginx 运行多个站点,类似于 apache vhost。

/etc/nginx/sites-enabled中,您可以添加两个虚拟主机

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;
       }
}

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;
       }
}

关于wordpress - 我们可以将 nginx 同时用于 WordPress 和 Drupal 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15216262/

相关文章:

drupal - 如何在 Drupal 6 的用户/注册表单中添加语言切换器

java - Tomcat 8.5 - 缓存警告泛滥

java - 使用 persistence.xml 创建 Hibernate SessionFactory

HTTPS 上的 Wordpress 前端,HTTP 上的后端

css - WooSlider 最大高度

php - 'woocommerce_login_redirect' 过滤器 Hook 问题

drupal - 显示区 block 中的节点信息

php - db_affected_rows() 始终返回 false

java - 是否可以将属性定义从配置移动到资源?

php - 仅显示三级 Wordpress 菜单