在nginx中创建虚拟主机以托管NodeJS应用程序

时间:2016-11-20 12:13:16

标签: node.js apache ubuntu nginx gitlab

以前,我使用Apache代理托管我的NodeJS应用程序,并在虚拟主机中进行以下配置。

<VirtualHost *:80>
  ServerName api.mydomain.com
  ProxyPreserveHost On
  ProxyPass / http://localhost:8090/
  ProxyPassReverse / http://localhost:8090/
  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

现在我因为GitLab依赖而转移到NGINX

现在是/etc/nginx/sites-available/api.mydomain.com

下的虚拟主机
server {
    listen 80;

    server_name api.mydomain.com;

    location / {
        proxy_pass http://localhost:8090;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
     }
}

但是域加载主要主机内容,而不是nodejs app。

nginx版本nginx/1.10.1,ubuntu版本16.04

下面是gitlab唯一的另一个虚拟主机,

upstream gitlab-workhorse {
  server unix:/var/opt/gitlab/gitlab-workhorse/socket;
}

## Normal HTTP host
server {
  ## Either remove "default_server" from the listen line below,
  ## or delete the /etc/nginx/sites-enabled/default file. This will cause gitlab
  ## to be served if you visit any address that your server responds to, eg.
  ## the ip address of the server (http://x.x.x.x/)n 0.0.0.0:80 default_server;
  listen 0.0.0.0:80 default_server;
  listen [::]:80 default_server;
  server_name gitlab.mydomain.com
  server_tokens off; ## Don't show the nginx version number, a security best practice
  root /opt/gitlab/embedded/service/gitlab-rails/public;

  ## See app/controllers/application_controller.rb for headers set

  ## Individual nginx logs for this GitLab vhost
  access_log  /var/log/nginx/gitlab_access.log;
  error_log   /var/log/nginx/gitlab_error.log;

  location / {
    client_max_body_size 0;
    gzip off;

    ## https://github.com/gitlabhq/gitlabhq/issues/694
    ## Some requests take more than 30 seconds.
    proxy_read_timeout      300;
    proxy_connect_timeout   300;
    proxy_redirect          off;

    proxy_http_version 1.1;

    proxy_set_header    Host                $http_host;
    proxy_set_header    X-Real-IP           $remote_addr;
    proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;
    proxy_set_header    X-Forwarded-Proto   $scheme;

    proxy_pass http://gitlab-workhorse;
  }
}

1 个答案:

答案 0 :(得分:0)

您可能没有在sites-enabled中创建指向sites-available中配置的符号链接,因此实际上并未读取配置。