Question about http: how do you view your server on a local network

xuanbao · · 688 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I am relearning golang but more specifically I don&#39;t know how http works in general. On all the tutorials for http in golang they use http.ListenAndServe(&#34;:8000&#34;, nil) to start the http server but they tell you to view the result at http://localhost:8000. How would I view it on the local network as 192.168.1.8:8000 if that was my computers ip on the network? Do I have to set up the http server in golang any differently?</p> <hr/>**评论:**<br/><br/>nowayno: <pre><p>Not sure I understand the question. To access the web server from another app on the same computer, you use localhost:8000 (or 127.0.0.1:8000 should work too), and to access the web server from another computer you&#39;d use the IP address like 192.168.1.8:8000. You don&#39;t have to do anything special.</p></pre>likehowdoi: <pre><p>If I understand your question correctly, you have a development server on your LAN, but are using a different computer to log in and develop. </p> <p>I believe it&#39;s your firewall preventing other LAN computers (and remote alike) from connecting to port 8000. Check this first before anything. It shouldn&#39;t effect anything if you are using the same machine for everything. But it sounds like you want to view the page on a different machine.</p> <p>Just open a browser like firefox and open http://localhost:8000 and then on a different pc on the LAN visit <a href="http://192.168.1.8:8000" rel="nofollow">http://192.168.1.8:8000</a></p> <p>if you are logged in SSH, just use curl or w3m to view your localhost site and see if it works. If you are trying to use your browser from a different machine you would have to open port 8000 on the server end.</p> <p>On a local network you would have to open firewall port as well. If you don&#39;t have apache or nginx (or another server) already on port 80, you can probably just use 80. Then you can type <a href="http://192.168.1.8" rel="nofollow">http://192.168.1.8</a> in a browser on the LAN. </p> <p>There are many request types, you probably have heard of POST, GET, there are others as well. When you visit a web site it is a GET request, when you &#34;post&#34; or &#34;upload&#34;, it is a POST request. (generally.)</p> <p>Optional: Try adding a line in your /etc/hosts file to bypass DNS and use your own fun domain names:</p> <p>192.168.1.8 funtime.com funtime</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

688 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传