首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Nginx的Dockerfile

Nginx的Dockerfile
EN

Stack Overflow用户
提问于 2019-09-30 09:31:47
回答 1查看 199关注 0票数 0

我已经建立了一个React SPA。

在我的packer-main.json中,我有以下配置:

代码语言:javascript
复制
{
    "variables": {
      "version": "{{ env `CI_PIPELINE_IID` }}"
    },
    "builders": [{
      "type": "docker",
      "image": "IMAGE NAME",
      "ecr_login": "true",
      "login_server": "LOGIN DETAILS",
      "commit": "true",
      "run_command": [ "-d", "-t", "-i", "{{.Image}}", "/bin/sh" ],
      "changes": [
        "EXPOSE 8080",
        "CMD [\"/usr/bin/openresty\"]"
    ]
    }],
    "provisioners": [
      {
        "type": "file",
        "only": ["docker"],
        "source": "build/",
        "destination": "/usr/local/openresty/nginx/html"
      },
      {
        "type": "shell",
        "inline": [
        "echo \"daemon off;\" >> /usr/local/openresty/nginx/conf/nginx.conf",
        "echo \"server { location / {# Set path root /var/www/; try_files $uri /index.html; } }  \" >> /usr/local/openresty/nginx/conf/nginx.conf"
        ]
      }
    ],
    "post-processors": [
      [
        {
          "type": "docker-tag",
          "repository": "my repo",
          "tag": "{{ user `version` }}"
        },
        {
          "type": "docker-push",
          "ecr_login": true,
          "login_server": "SERVER ADDRESS"
        }
      ]
    ]
}

我得到以下错误:

代码语言:javascript
复制
nginx: [emerg] "server" directive is not allowed here in /usr/local/openresty/nginx/conf/nginx.conf:118

下面是我的nginx.conf:

代码语言:javascript
复制
#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
error_log   /dev/stderr     info;

#pid        logs/nginx.pid;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /dev/stdout;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen   8080;
        server_name  localhost;

        port_in_redirect off;

        location / {
            root   /usr/local/openresty/nginx/html;
            index  index.html index.htm;
            try_files $uri $uri/ /APPS-UI/src/index.html;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/local/openresty/nginx/html;
        }


    }
}

我需要将我的应用程序重定向到index.html,这目前还没有发生。当我加载页面时,它工作得很好,只有当我在应用程序中刷新页面时,它才会给出500个错误。

EN

回答 1

Stack Overflow用户

发布于 2019-09-30 13:55:42

您需要将server in http指令放在nginx.conf

代码语言:javascript
复制
echo "http {server { location / {# Set path root /var/www/; try_files $uri /index.html; } }}"
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58160539

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档