Dockerfile для Nginx - PullRequest
       11

Dockerfile для Nginx

0 голосов
/ 30 сентября 2019

Я собрал React SPA.

В моем пакере main.json у меня есть следующая конфигурация:

{
    "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"
        }
      ]
    ]
}

Я получаю следующую ошибку:

nginx: [emerg] "server" directive is not allowed here in /usr/local/openresty/nginx/conf/nginx.conf:118

Ниже мой nginx.conf:

#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.

1 Ответ

1 голос
/ 30 сентября 2019

вам нужно поместить server в директиву http в вашей nginx.conf

echo "http {server { location / {# Set path root /var/www/; try_files $uri /index.html; } }}"
...