Nginx的Dockerfile
我已经建立了一个React SPA。
在我的packer-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
我需要将我的应用程序重定向到当前未发生的index.html。
回答如下:您需要在server
中的http
指令中放置nginx.conf
echo "http {server { location / {# Set path root /var/www/; try_files $uri /index.html; } }}"