如何将我的 meteor 应用程序部署到本地网络中的 Ubuntu 服务器?

How can I deploy my meteor app to an Ubuntu server in my local network?

我有一个简单的 meteor 应用程序,我希望它 运行 在本地计算机上 运行ning Ubuntu 在我的本地网络中使用 nginx 以便可以从使用机器的本地 IP 地址浏览器。我试过使用 mup (meteor up) 但它需要 SSH 密钥而且我必须使用 nginx 所以我必须手动部署。

如果你能帮我部署应用程序,我将不胜感激,我可以使用和尝试不同的方法,只要它是 运行 nginx。

此时我不需要 SSL,所以我想跳过这一步。另外,我的 MongoDB 服务器将在同一台机器上连接到 运行,所以我也试图在本地访问它。我已经尝试过这个永远使用到 运行 meteor link 的教程 但我想不出 运行 它,它也没有解释如何配置我的 MongoDB URL 和东西。

我已经安装了 node,forever 和 meteor,创建了一个新用户,将我的存储库克隆到我的家庭服务器,我可以 运行 在本地使用“meteor 运行”命令。

我认为我在配置 nginx 和捆绑我提到的教程中解释的应用程序的脚本时遇到问题。我不确定在哪里可以找到 env_settings.sh 文件。它在我的 /etc/nginx/ 目录中。

这是我的 nginx 配置 文件

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

env_settings.sh

#load environment variables
source ../env_settings.sh

meteor update --release 1.11 #ensure proper version of Meteor

npm install # install NPM dependencies
npm prune --production # remove development dependencies

rm -rf ~/bundle # remove the previous bundle

meteor build --directory ~ # build the current bundle

cd ~/bundle/programs/server # enter the bundle
npm install # install dependencies

mv ~/bundle ~/portal 

# make sure the logs directory exists
mkdir ~/logs 

# use forever to restart the Node.js server
export PORT=8080
cd ~/portal
forever stop main.js
forever start -a -l ~/logs/forever.log -o ~/logs/portal.out -e ~/logs/portal.err main.js

sites_available/app

# this section is needed to proxy web-socket connections
map $http_upgrade $connection_upgrade {
        default upgrade;
        ''      close;
}
# HTTP
server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;
        
        location = /favicon.ico {
          root /home/webapp/portal/programs/web.browser/app;
          access_log off;
        }
        
        location ~* "^/[a-z0-9]{40}\.(css|js)$" {
          gzip_static on;
          root /home/webapp/portal/programs/web.browser;
          access_log off;
        }
        
        location ~ "^/packages" {
          root /home/webapp/portal/programs/web.browser;
          access_log off;
        }

        # pass requests to Meteor
        location / {
            proxy_pass http://127.0.0.1:8080;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade; #for websockets
            proxy_set_header Connection $connection_upgrade;
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_set_header Host $host;
        }
}
  1. 你应该 运行 它与 node main.js 而不是 main.js

  2. 在 运行 之前,您应该定义以下环境变量:

    导出端口=8080

    导出ROOT_URL=http://your.site.name

    导出MONGO_URL=mongodb://127.0.0.1/your.database.name

您可以创建一个 .service 文件,这样如果服务停止,它将在 Ubuntu 后重新启动。这是一个例子:

[Unit]
Description=Meteor app

[Service]
ExecStart=/usr/bin/node /home/user/meteorapp/bundle/main.js
User=user
Group=user
WorkingDirectory=/home/user/meteorapp/bundle
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=meteorapp
Environment=PWD=/home/user/meteorapp/
Environment=MONGO_URL=mongodb://localhost:27017/meteorapp
Environment=HTTP_FORWARDED_COUNT=1
Environment=PORT=8094
Environment=apiPort=4080
Environment=ROOT_URL=http://192.168.1.1
Environment=BIND_IP=127.0.0.1
Environment='METEOR_SETTINGS={"private": {"key": "value"}}'

[Install]
WantedBy=multi-user.target

将此文件放入 /etc/system/systemd,然后您可以使用 sudo service meteorapp start 启动。

如果您是 运行在本地进行此操作,则不需要使用 nginx。我 运行 meteor 应用程序一直在本地使用 meteor 并且所有设备都可以在内部访问它。

*注意:以上脚本仅在您已经构建了 meteor 应用程序时才有效。但我会选择 运行ning 只使用 meteor 命令并以这种方式访问​​。如果您想使用单独的 MongoDB 数据库,您可以创建一个简单的 ./start 脚本。

 export MONGO_URL=mongodb://localhost:27017/meteorapp
 meteor --settings settings.json --port 3004

使该文件可执行,然后您就可以 运行 在本地使用它。

我已经根据link中的信息处理了这种情况。它不是 运行 流星的捆绑版本,但这实际上是一种更好的方法,可以更轻松地在本地网络上进行测试。