我有一个简单的流星应用程序,我希望它运行在使用nginx在我的本地网络中运行Ubuntu的本地计算机上,以便可以使用该计算机的本地IP地址从浏览器访问它。我曾尝试使用mup(流星雨),但它需要SSH密钥,并且必须使用nginx,因此必须手动进行部署。
如果您可以帮助我部署该应用程序,只要它与nginx一起运行,我可以使用并尝试其他方法,将不胜感激。
目前我不需要SSL,因此我试图跳过这一步。另外,我的MongoDB服务器将在同一台计算机上运行,因此我也尝试在本地访问该服务器。我已经尝试过永远使用流星link的本教程 但是我无法运行它,也无法解释如何配置MongoDB URL和内容。
我已经安装了永久和流星节点,创建了一个新用户,将我的存储库克隆到我的主服务器中,并且可以在本地使用“ meteor run”命令来运行它。
我认为我在配置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;
}
}
答案 0 :(得分:0)
您应该使用node main.js
而不是main.js
在运行它之前,应定义以下环境变量:
导出PORT = 8080
导出ROOT_URL = http://your.site.name
导出MONGO_URL = mongodb://127.0.0.1/your.database.name
答案 1 :(得分:0)
您可以创建一个.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命令并以这种方式访问。如果要使用单独的MongoDB数据库,则可以创建一个简单的./start
脚本。
export MONGO_URL=mongodb://localhost:27017/meteorapp
meteor --settings settings.json --port 3004
使该文件成为可执行文件,您可以通过这种方式在本地运行它。
答案 2 :(得分:0)
我已使用此link中的信息处理了这种情况。它没有运行捆绑版的流星,但这实际上是一种更好的方法,可以使它更容易在本地网络上进行测试。