<p>Hi, I am new in Go. Until now, i worked on local but now i want to deploy my web project to server. My friend who interested in golang said me that i should copy my webapp folder to src folder in my GOPATH and enter 'go build' command in there. After that process i obtained an exe file, he told me to deplay that exe to server. I deployed but it doesn't work. Did i do something wrong or i need to do something more? What should i do with that exe file? Thanks and have a good day!</p>
<p>EDIT: My server using Linux</p>
<hr/>**评论:**<br/><br/>very-little-gravitas: <pre><p>Make sure you are cross compiling - if you do the app won't work locally but should work on the server. See example command below to cross compile. </p>
<p>I usually host simple go apps on coreos without docker (I know :) as standalone apps - nothing required except a unit file and the go app + templates. You can use a go binary cross compiled and rsynced up with any support files required. Same process applies to ubuntu say. </p>
<ol>
<li>Set up a service (usually systemd nowadays) on the server pointing to your binary location</li>
</ol>
<p>Then to deploy each time take these steps (I use a bash script):</p>
<ol>
<li>local: GOOS=linux GOARCH=arm go build server.go</li>
<li>local: rsync the binary up to server</li>
<li>on server: sudo systemctl restart myserver.service</li>
</ol>
<p>I don't bother with these for go apps:</p>
<ul>
<li>Compiling on the server (requires a full go build setup on the server)</li>
<li>Docker (unreliable, another part which can break, and go apps don't have dependencies)</li>
<li>Proxies (unless you want to share one server between apps)</li>
</ul></pre>hybsuns: <pre><p>The general strategy is that you run a Go app behind a reverse proxy, typically Nginx. The basic workflow is that you configure Nginx to listen on port 80 or 443, and pass calls to your local Go app, which may listen on port 8080 or 8000. You run your Go app as a systemd service so that the application can keep running even if you logout your server.</p>
<p>Here is what I do:</p>
<ol>
<li><p>Mirror your server environment the same as your development environment: install Go library, database (optional), other tools.</p></li>
<li><p>Install Nginx</p></li>
<li><p>Pull your Go source code to the GOPATH on your server, and build your Go app on your server. You may need to change your configuration since your server environment is typically different from your local development environment.</p></li>
<li><p>Write a systemd service file and run your Go app as a service using systemd.</p></li>
<li><p>Write your configuration for Nginx so that calls to port 80/443 are forwarded to your Golang app, which is on port 8080 or 8000.</p></li>
<li><p>Start your Nginx and Systemd, and you app should be running on your server now (if no error occurs).</p></li>
</ol>
<p>You may also need to configure your DNS, Firewalls, and SSL Certificates, but they are beyond the scope of this topic.</p>
<p>DigitalOcean has a lot of good posts about how to configure all these settings. </p>
<p><a href="https://wiki.danceinsight.com/index.php/DAS_Application_Server_Setup" rel="nofollow">Here</a> is a wiki for my own Golang app server settings. It's far from complete but should be an okay start: </p></pre>bahadirtuna34: <pre><p>Thank you so much,this informations are very helpful</p></pre>stefanfransen: <pre><p>Is your server running Linux or Windows?</p></pre>bahadirtuna34: <pre><p>Linux</p></pre>tv64738: <pre><blockquote>
<p>but it doesn't work.</p>
</blockquote>
<p>How about you provide a little more information?</p></pre>mrmylanman: <pre><p>Here's how I do it on FreeBSD (which would work about the same as Linux). On the server I run the app behind nginx, so I can easily serve statically-gzipped assets and stuff.</p>
<p>I use make to coordinate different build tasks, and one of those is <code>deploy</code>. My deploy task does the following:</p>
<ol>
<li>Build the server and the JS client (using an NPM task)</li>
<li>Runs a command via ssh to put the app into "maintenance mode" (tells nginx to serve a static html page saying it's under maintenance)</li>
<li>Runs a command via ssh to stop the app's services</li>
<li>Deploy the app's compiled binary and public directory to the server</li>
<li>Runs a command via ssh to perform any necessary database migrations</li>
<li>Runs a command via ssh to start the app's services</li>
<li>Runs a command via ssh to stop maintenance mode</li>
</ol>
<p>I was thinking about posting more particulars of how I manage all this, since it works well for me, although it's certainly not as "cool" as Docker.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传