简体   繁体   English

NixOps-使用Python Flask配置Nginx代理传递

[英]NixOps - Configure Nginx proxy pass with Python Flask

I am new to Nix and trying to implement a service which passes Python Flask web services though Nginx proxy_pass . 我是Nix的新手,正在尝试实现通过Nginx proxy_pass传递Python Flask Web服务的服务。 This is what I have tried so far. 到目前为止,这是我尝试过的。

with import <nixpkgs> {};


    let
        buildInputs = [
            nginx
            python35Packages.python
            python35Packages.flask
            python35Packages.pyyaml
        ];

        installPhase = ''
            mkdir -p $out/pynix
            cp -rv src config.yml $out/pynix
            cd $out/pynix && nohup python src/main.py &> log.txt
        '';


    in {
        network.description = "Local machine";

        webserver = {
            deployment = {
                targetEnv = "virtualbox";
                virtualbox.memorySize = 1024;
            };

            services = {
                nginx = {
                    enable = true;
                    config = '';
                        http {
                            include         ${nginx}/conf/mime.types;
                            server_name     localhost;

                            location / {
                                proxy_pass http://localhost:5000;
                            }
                        }
                    '';
                };
            };
        };
    }

src/main.py is a Python Flask service running on port 5000. How can I achieve this web service up and running when I do nixops deploy -d DEPLOYMENT_NAME ? src/main.py是在端口5000上运行的Python Flask服务。当我执行nixops deploy -d DEPLOYMENT_NAME时,如何实现并运行该Web服务? Please help. 请帮忙。

I think you've confused a package and a service. 我认为您已经混淆了包裹和服务。 The package is the static output of the build while the service manages the run time activation of the package. 程序包是构建的静态输出,而服务则管理程序包的运行时激活。 I think your configuration currently attempts to describe a python app that is run at build time without any service to activate it at run time. 我认为您的配置当前尝试描述在构建时运行的python应用程序,而没有任何在运行时激活它的服务。 This is pretty much the opposite of what you want! 这几乎与您想要的相反! Especially as with nixops your are likely running your service in a different environment to where it was built. 尤其是与nixops一样,您可能会在与构建服务不同的环境中运行服务。
You should be able to get an idea of what I mean by looking at the nix expressions for the nginx package and the nginx service - specifically the section services.systemd.nginx . 通过查看nginx 软件包和nginx 服务的nix表达式(特别是部分services.systemd.nginx您应该能够理解我的意思。 From here you can see that the nginx service manages the running of the nginx package . 从这里您可以看到nginx 服务管理着nginx 软件包的运行。 I think you will want to write similar expressions for your python app. 我认为您将希望为python应用程序编写类似的表达式。 You could also see if there are expressions specifically for python based NixOS services that you could use as a base, but the nginx expressions should be a sufficient guide too. 您还可以查看是否有专门用于基于python的NixOS服务的表达式,您可以将其用作基础,但是nginx表达式也应该是足够的指南。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM