注意,編譯項目文件時所使用的操做系統要與服務器一致,例如須要運行在Ubuntu64上的項目,就須要在Ubuntu64的環境裏編譯。nginx
{:exrm, "~> 1.0"}
到mix.exs
文件config/prod.exs
# Configures the endpoint config :hello_phoenix, HelloPhoenix.Endpoint, http: [port: 8888], url: [host: "example.com"], root: ".", cache_static_manifest: "priv/static/manifest.json", server: true, version: Mix.Project.config[:version]
$ MIX_ENV=prod mix phoenix.digest ==> ranch (compile) . . . Check your digested files at 'priv/static'.
MIX_ENV=prod mix compile
MIX_ENV=prod mix release
rel/hello_phoenix/bin/hello_phoenix console
$ scp -i ~/.ssh/id_rsa.pub rel/hello_phoenix-0.0.1.tar.gz ubuntu@hostname.com:/home/ubuntu hello_phoenix-0.0.1.tar.gz 100% 18MB 80.0KB/s 03:48
$ ssh -i ~/.ssh/id_rsa.pub ubuntu@hostname.com $ sudo mkdir -p /app $ sudo chown ubuntu:ubuntu /app $ cd /app $ tar xfz /home/ubuntu/hello_phoenix-0.0.1.tar.gz
sudo vi /etc/init/hello_phoenix.conf
description "hello_phoenix" ## Uncomment the following two lines to run the ## application as www-data:www-data #setuid www-data #setgid www-data start on runlevel [2345] stop on runlevel [016] expect stop respawn env MIX_ENV=prod export MIX_ENV ## Uncomment the following two lines if we configured ## our port with an environment variable. env PORT=8888 export PORT ## Add app HOME directory. env HOME=/app export HOME pre-start exec /bin/sh /app/bin/hello_phoenix start post-stop exec /bin/sh /app/bin/hello_phoenix stop
sudo start hello_phoenix
$ sudo touch /etc/nginx/sites-available/hello_phoenix $ sudo ln -s /etc/nginx/sites-available/hello_phoenix /etc/nginx/sites-enabled $ sudo vi /etc/nginx/sites-available/hello_phoenix
upstream hello_phoenix { server 127.0.0.1:8888; } # The following map statement is required # if you plan to support channels. See https://www.nginx.com/blog/websocket-nginx/ map $http_upgrade $connection_upgrade { default upgrade; '' close; } server{ listen 80; server_name .hostname.com; location / { try_files $uri @proxy; } location @proxy { include proxy_params; proxy_redirect off; proxy_pass http://hello_phoenix; # The following two headers need to be set in order # to keep the websocket connection open. Otherwise you'll see # HTTP 400's being returned from websocket connections. proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; } }
sudo service nginx restart
http://hostname.com/
訪問Phoenix應用了。