在Windows Server 2008上部署Go Web项目

我的项目:转到-1.12.5; 杜松子酒gonic; vue-cli-3.8.2。</ p>

在Windows Server 2008上,请在本地帐户下运行main.exe-效果很好。 但是,注销帐户后,所有本地帐户程序(包括我的go服务器)都将关闭。</ p>

我做的第一件事是尝试为GO配置IIS。 </ p>

然后我尝试从SYSTEM帐户 psexec -s c:afd \ main.exe </ strong>运行main.exe。 注销后,该过程不会关闭。 但是前端在我的帐户中,SYSTEM看不到我项目的本地文件(js,html,css)</ p>

告诉我如何启动Go服务器,注销后 项目没有停止生命</ p>
</ div>

展开原文

原文

My project: go - 1.12.5; gin-gonic; vue-cli - 3.8.2.

On windows server 2008 go under the local account, run main.exe - works well. But when log off my account, all local account programs are closed, including my go server.

The first thing I did was try to configure IIS for my GO. Nothing good came of it.

Then I tried to run main.exe from the SYSTEM account psexec -s c:afd\main.exe. When log off the process does not close. But the frontend is in my account and SYSTEM does not see the local files (js, html, css) of my project

Tell me how to start the Go server, to after log off my project did not stop life

doujiang1939
doujiang1939 我用代码GO全路径dist(html,css,js)编写了代码,并且运行良好
一年多之前 回复
dongse7261
dongse7261 最后一个选项可能是最接近的。您只需要将必要的文件放入具有其运行帐户的正确权限的位置,即可访问它们。
一年多之前 回复

2个回答

Two ways to approach it.

  1. Go with ISS (or another web server).

    Should you pick this option, you have further choices:

    • Leave your project's code as is, but

      • Make sure it's able to be told which socket to listen for connections on—so that you can tell it to listen, say, on localhost:8080. For instance, teach your program to accept a command-line parameter for that—such as -listen or whatever.
      • Configure IIS in a way so that it reverse-proxies incoming HTTP requests on a certain virtual host and/or path prefix to a running instance of your server. You'll have to make the IIS configuration—the socket it proxies the requests to—and the way IIS starts your program agree with each other.
    • Rework the code to use FastCGI protocol instead. This basically amounts to using net/fastcgi instead of net/http.

      The upside is that IIS (even its dirt-old versions) support FastCGI out of the box. The downsides are that FastCGI is beleived to be slightly slower than plain HTTP in Go, and that you'll lose the ability to run your program in the standalone mode.

  2. Turn your program into a proper Windows™ service or "wrap" it with some helper tool to make it a Windows™ service.

    The former is cleaner as it allows your program to actually be aware of control requests the Windows Service Management subsystem would send to you. You could also easily turn your program into a shrink-wrapped product, if/when needed. You could start with golang.org/x/sys/windows/svc.

    The latter may be a bit easier, but YMMV. If you'd like to explore this way, look for tools like srvany, nssm, winsv etc.

    Note that of these, only srvany is provided by Microsoft® and, AFAIK, it's missing since Win7, W2k8, so your best built-in bet might be messing with sc.exe.

    In either case, should you pick this route, you'll have to deal with the question of setting up proper permissions on your app's assets. This question is reasonably complex in itself since there are many moving parts involved.

    For a start, you have to make sure your assets are tried to be accessed not from "the process' current directory"—which may be essentially random when it runs as a service—but either from the place the process was explicitly told about when run (via command-line option or whatever) or figured out somehow using a reasonably engeneered guess (and this is a complicated topic in itself).

    Next, you either have to make sure the account your Windows™ uses to run your service really has the permissions to access the place your assets are stored in. Another possibility is to add a dedicated account and make the SCM use it for running your service.

    Note that in either case proper error handling and their reporting is paramount: when your program is being run non-interactively, you want to know when something goes wrong: socket failed to be opened or listened on, assets not found, access was denied when trying to open an asset file, and so on—in all these cases you have to 1) handle the error, and 2) report it in a way you can deal with it. For a non-interactive Windows™ program the best way may be to use the Event Log (say, via golang.org/x/sys/windows/svc/eventlog).

dougui1977
dougui1977 无论如何,权限都是一个问题。 默认情况下,IIS和Windows Services都作为系统帐户运行。
一年多之前 回复



最简单的解决方案是使用计划的Windows。</ p>

在系统登录时以最高级别启动exe文件 特权在背景中。 因此,只要您的系统登录,它就会启动exe并在后台运行。</ p>

您可以参考此答案,
</ p>
</ div>

展开原文

原文

Simplest solutions would be using windows schedular.

Start your exe file on system logon with highest privilage in background. So whenever your system will logon it will start your exe and make runnign in background.

You can refer this answer, How do I set a Windows scheduled task to run in the background?

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐