如何在Centos7上部署Meteor应用程序到生产服务器

3
如何在CentOS7中部署Meteor。我们已经安装了Meteor、MeteorJS和Node.js包,但是我们无法打开生产链接。请帮助我进行解决。
1个回答

5
  • First of all, you don't need to install meteor on production server. Node.js is enough.
  • On my Centos server, I use nginx + supervisord to run my meteor app.
  • You should build your app with "meteor build --directory " command. With this command you will get a bundle directory. Compress that bundle folder and upload it to the server. Example

    meteor build --directory <some_path>
    
  • Extract in on the server, then

    cd bundle/programs/server
    npm install
    
  • Example meteor app config in supervisord.conf file. All the meteor app specific config is in the 'environment' variable on this configuration. There will be other entries in your supervisord.conf file. You will have to add this one for your meteor app. For more info on supervisord, visit http://supervisord.org

    [program:my-meteor-app]
    command=node main.js              ; the program (relative uses PATH, can take args)
    directory=/home/path_where_bundle_is/bundle
    process_name=%(program_name)s ; process_name expr (default %(program_name)s)
    numprocs=1                    ; number of processes copies to start (def 1)
    autostart=true                ; start at supervisord start (default: true)
    autorestart=unexpected        ; whether/when to restart (default: unexpected)
    user=app_user                   ; setuid to this UNIX account to run the program
    redirect_stderr=true          ; redirect proc stderr to stdout (default false)
    stdout_logfile=/var/log/meteor.log        ; stdout log path, NONE for none; default AUTO
    stdout_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
    stdout_logfile_backups=10     ; # of stdout logfile backups (default 10)
    ;stdout_capture_maxbytes=1MB   ; number of bytes in 'capturemode' (default 0)
    ;stdout_events_enabled=false   ; emit events on stdout writes (default false)
    stderr_logfile=/var/log/meteor_err.log        ; stderr log path, NONE for none; default AUTO
    stderr_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
    stderr_logfile_backups=10     ; # of stderr logfile backups (default 10)
    ;stderr_capture_maxbytes=1MB   ; number of bytes in 'capturemode' (default 0)
    ;stderr_events_enabled=false   ; emit events on stderr writes (default false)
    environment=PORT="3003", ROOT_URL="https://your_url",MAIL_URL="smtp://xxx:xxx@smtp.mailgun.org:25",MONGO_URL="mongodb://xxx:xxx@localhost/databasename"       ; process environment additions (def no adds)
    ;serverurl=AUTO                ; override serverurl computation (childutils) 
    
  • For nginx configuration, this is my configuration concerning meteor app (this is not the whole config file just the part necessary for meteor):

        location / {
       proxy_pass http://localhost:3003/;
       proxy_set_header Host $host;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection "upgrade";
       proxy_http_version 1.1;
    }
    

如需更详细的关于nginx的设置信息,请查看digitalocean文档:https://www.digitalocean.com/community/tutorials/how-to-deploy-a-meteor-js-application-on-ubuntu-14-04-with-nginx

当一切正常时:

    supervisorctl start all
    service nginx start
  • I am running meteor app on port 3003 and redirecting requests to that port using nginx. You might want to add an iptables rule to drop connections to port 3003, so that only nginx can connect to port 3003. Here are two iptables rules to deny mongodb and port 3003 connections from public networks.

    iptables -A INPUT -i eth0 -p tcp -m tcp --dport 27017 -j DROP
    iptables -A INPUT -i eth0 -p tcp -m tcp --dport 3003 -j DROP
    

我按照你的回答尝试了一下,确实有效,谢谢。但现在,我想在另一个位置(例如/app)运行我的Meteor应用程序。但是,当我更改“location /app {...}”时,它显示我的应用程序的404页面。有什么想法吗?谢谢。 - Benjamin Lucidarme

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接