繁体   English   中英

部署 docker、nginx 并做出反应

[英]deploying docker, nginx and react

我用 React 完成了申请。 我想在 docker 容器上运行它并将其呈现给用户。 当我输入http://localhost:8000时我可以访问反应,但是当我输入http://localhost我不能访问反应

我希望默认反应应用程序查看用户何时键入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;
  #}
}

我尝试了与您的配置完全匹配的配置。 我已经使用了您提供的两个 docker 文件,并且我还使用了一个 react 应用程序。 运行命令时发布端口 80 对我有用。 这个命令:

docker container run -p 80:80 nginx-react:latest

在这种情况下,在构建 nginx 映像时,我将其命名为 nginx-react 并标记为 latest。

如果该命令对您不起作用。 您能否分享您正在使用的机器的已知主机列表? 如果您不确定在哪里可以找到您机器上的主机列表,请查看链接。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM