【问题标题】:Creating virtualhost in nginx to host NodeJS app在 nginx 中创建虚拟主机来托管 NodeJS 应用程序
【发布时间】:2016-11-21 20:49:08
【问题描述】:

以前,我使用 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 应用程序。

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

【问题讨论】:

  • 目前,通过同时运行 nginx 和 apache 作为代理解决了这个问题。但仍在寻找问题。

标签: node.js apache ubuntu nginx gitlab


【解决方案1】:

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

【讨论】:

  • 你能给我举个例子吗?据我了解,nginx 查看站点可用文件夹本身。不知道它是否正确。
  • /etc/nginx/nginx.conf 中查找include 指令,如果它显示sites-available/*,则为是,否则您需要像这样创建符号链接:sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/api.mydomain.com
猜你喜欢
  • 2015-07-30
  • 1970-01-01
  • 2013-01-17
  • 2018-10-10
  • 2015-09-16
  • 2011-01-11
  • 2012-09-15
  • 2014-07-10
  • 2018-06-29
相关资源
最近更新 更多