【问题标题】:How to define nginx root when using a custom runtime in Google App Engine?在 Google App Engine 中使用自定义运行时如何定义 nginx root?
【发布时间】:2018-05-18 03:12:38
【问题描述】:

我正在使用 Google App Engine Flex,需要使用自定义运行时,以便安装一些第三方库。我需要将 document_root 定义为“public”,只有 runtime_configs 似乎在使用自定义运行时时被忽略,所以这不起作用:

runtime_config:
   document_root: public

我还尝试添加一个声明了根目录的 nginx-app.conf 文件(我也不确定如何获取应用程序路径,所以我只是对其进行了硬编码):

root "/app/public";

但我得到了错误:

nginx: [emerg] "root" 指令在 /etc/nginx/conf.d/nginx-app.conf:1 中重复

我无法在文档中找到此问题的答案,因此感谢您的帮助!

【问题讨论】:

    标签: google-app-engine nginx yaml


    【解决方案1】:

    Hello World example之后,您可以看到根文件夹在您的案例nginx-app.conf的nginx配置文件中声明

    首先你必须正确配置你的Docker文件,这将创建公用文件夹并将所有文件从本地机器复制到它:

    FROM nginx
    
    COPY nginx.conf /etc/nginx/nginx.conf
    
    RUN mkdir -p /usr/share/nginx/public/
    
    # Copy static files from local public folder
    ADD public/ /usr/share/nginx/public/
    RUN chmod -R a+r /usr/share/nginx/public
    

    您必须在nginx-app.conf 文件中定义该公用文件夹的路径:

    http {
        server {
            root /usr/share/nginx/public;
        }
    }
    

    【讨论】:

    • 这正是我所追求的!尽管您似乎不能使用 nginx-app.conf 因为这只会附加到默认的 nginx.conf (这是导致我的问题的原因)。所以你说得对,我需要制作一个全新的 nginx.conf 并通过 Docker 脚本复制它。
    • @BenSouthall 我尝试替换 nginx.conf 文件,但没有成功,仍然没有按照我定义的那样扎根,您还需要做些什么才能让它工作吗?跨度>
    猜你喜欢
    • 2020-05-06
    • 2015-06-13
    • 2018-10-14
    • 1970-01-01
    • 1970-01-01
    • 2017-04-08
    • 1970-01-01
    • 2015-11-07
    • 2016-08-08
    相关资源
    最近更新 更多