[英]How can I deploy my meteor app to an Ubuntu server in my local network?
I have a simple meteor app, I want it to run on a local machine running Ubuntu in my local network with nginx so that it can be reachable from the browser with the machine's local IP address.我有一个简单的流星应用程序,我希望它在本地网络中使用 nginx 运行 Ubuntu 的本地机器上运行,以便可以从具有机器本地 IP 地址的浏览器访问它。 I have tried using mup (meteor up) but it requires SSH keys and I have to use nginx so I have to deploy manually.
我曾尝试使用 mup (meteor up),但它需要 SSH 密钥,而且我必须使用 nginx,所以我必须手动部署。
I would be appreciated if you can help me deploying the app, I can use and try different methods as long as it is running with nginx.如果您能帮助我部署应用程序,我将不胜感激,只要它与 nginx 一起运行,我就可以使用并尝试不同的方法。
I don't need SSL at this point so I am trying to skip that step.我此时不需要 SSL,所以我试图跳过这一步。 Also, my MongoDB server is going to run on the same machine so I am trying to reach that locally too.
此外,我的 MongoDB 服务器将在同一台机器上运行,所以我也试图在本地访问它。 I have tried this tutorial that is using forever to run meteor link but I couldn't figure to run it, also it does not explains how to configure my MongoDB URL and stuff.
我已经尝试过这个永远使用流星链接的教程,但我无法运行它,它也没有解释如何配置我的 MongoDB URL 和其他东西。
I have Installed node, forever & meteor, created a new user, cloned my repository to my home server and I can run it with "meteor run" command locally.我已经安装了节点,永远和流星,创建了一个新用户,将我的存储库克隆到我的主服务器,我可以在本地使用“meteor run”命令运行它。
I think I have problems with configuring nginx and the script that bundles the application that is explained in the tutorial I mentioned.我想我在配置 nginx 和捆绑我提到的教程中解释的应用程序的脚本时遇到了问题。 I am not sure where to locate the env_settings.sh file.
我不确定在哪里可以找到 env_settings.sh 文件。 It is on my /etc/nginx/ directory.
它在我的 /etc/nginx/ 目录中。
here is my nginx config file这是我的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 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;
}
}
You should run it with node main.js
and not main.js
您应该使用
node main.js
而不是main.js
运行它
Before running it, you should have the following env variables defined:在运行它之前,您应该定义以下环境变量:
export PORT=8080出口端口=8080
export ROOT_URL=http://your.site.name导出 ROOT_URL=http://your.site.name
export MONGO_URL=mongodb://127.0.0.1/your.database.name export MONGO_URL=mongodb://127.0.0.1/your.database.name
You can create a .service
file so if the service stops, it will restart in Ubuntu.您可以创建一个
.service
文件,这样如果服务停止,它将在 Ubuntu 中重新启动。 Here is an example:下面是一个例子:
[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
Put this file in /etc/system/systemd
and you can launch with sudo service meteorapp start
.将此文件放在
/etc/system/systemd
,您可以使用sudo service meteorapp start
。
If you are running this locally, you don't need to use nginx.如果您在本地运行它,则不需要使用 nginx。 I run meteor apps all the time locally with just
meteor
and it is accessible by all devices internally.我一直在本地只使用
meteor
运行meteor 应用程序,并且所有设备都可以在内部访问它。
*Note: The above script only works if you have already built the meteor app. *注意:以上脚本仅在您已经构建了流星应用程序时才有效。 But I would go with running just the meteor command and accessing that way.
但我会只运行meteor 命令并以这种方式访问。 If you want to use a separate MongoDB database, you can create a simple
./start
script.如果要使用单独的 MongoDB 数据库,可以创建一个简单的
./start
脚本。
export MONGO_URL=mongodb://localhost:27017/meteorapp
meteor --settings settings.json --port 3004
Make that file executable and you can run it locally that way.使该文件可执行,您可以通过这种方式在本地运行它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.