如何在同一台服务器上使用nginx配置php和nodejs app

时间:2014-06-16 11:53:34

标签: php node.js apache ubuntu nginx

我有一个Ubuntu VPC。我在某个文件夹中运行了一个nodejs应用程序。我有一个在var / www上的apache上运行的php应用程序。我想要的是配置nginx,以便当用户进入mydomain.com时,他/她被重定向到我在端口3000上运行的节点应用程序,当用户访问mydomain.com/docs时,他/她被重定向到我的php应用程序在端口80上的apache上运行。

server {
  listen 80;  
  root /var/www;

  location / {
    try_files $uri $uri/ /index.html;
  }

  location ~\.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
  }

  location /doc/ {
    alias /usr/share/doc/;
    autoindex on;
    allow 127.0.0.1;
    deny all;
  }

  location ~/\.ht {
    deny all;
  }
}

我的nodejs app的conf文件是:

upstream app_somedomain {
  server 127.0.0.1:3000;
}

server {
  listen 0.0.0.0:80;
  server_name mydomain.com mydomain;
  root /some/path;
  index index.html index.htm index.php index.js;

  location / {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_set_header X-NginX-Proxy true;
    proxy_pass http://app_somedomain/;
    proxy_redirect off;
  }
}

我第一次使用nginx。我仍然无法理解如何实现这一目标。如在如何将我在端口3000上运行的nodejs应用程序服务到我的域名和mydomain / docs到我的php应用程序。

感谢。

0 个答案:

没有答案