我用React完成了应用程序。 我想在docker容器上运行它并将其呈现给用户。 键入 http://localhost:8000 时可以访问react,但是键入 http://localhost 时不能访问react,即如何访问我键入时默认反应应用程序 http://localhost
我希望默认的React应用程序在用户键入http://localhost时看到它,您能帮我吗?
Dockerfile
# Stage 1
FROM node:8 as react-build
WORKDIR /app
COPY . ./
RUN yarn
RUN yarn build
# Stage 2 - the production environment
FROM nginx:alpine
COPY nginx-custom.conf /etc/nginx/conf.d/default.conf
COPY --from=react-build /app/build /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
nginx-custom.conf
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri /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/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
答案 0 :(得分:0)
我尝试了与您的配置完全匹配的配置。我已经使用了您介绍的两个docker文件,也使用了react应用程序。运行命令时发布端口80对我有用。该命令:
result, err := uploader.Upload(&s3manager.UploadInput{
Bucket: aws.String(targetS3Bucket),
Key: aws.String(documentKey),
Body: bytes.NewReader(buffer.Bytes()),
})
在这种情况下,构建nginx图像时,我将其命名为nginx-react并将其标记为最新。
如果该命令对您不起作用。您能否共享正在使用的计算机的已知主机列表?如果不确定在哪里可以找到计算机上的主机列表,请检查this链接。