Nginx在码头工人刷新时出现404错误?

时间:2018-09-24 00:35:56

标签: javascript node.js express docker nginx

使用其他标头刷新时出现404错误。我以前从未使用过Nginx。任何人都可以建议如何解决此错误?我尝试了多种解决方案,例如添加try_files $ uri /index.html;。到位置/,但不起作用。

我的前端,后端,数据库和代理服务器正在运行dockers。

这是我的Nginx default.conf

server {
listen 80;
server_name localhost;
client_max_body_size 10M;

location /api {
    proxy_pass http://server:5000/api;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection keep-alive;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_cache_bypass $http_upgrade;
}
location / {
    root /source;
    try_files $uri /index.html;
    index  index.html index.htm;
}

}

这是我的docker-compose.yml。我是否还需要为前端,后端,nginx共享卷?

version: '3'

services:

  client:
    restart: always
    build:
      context: ./client
      dockerfile: Dockerfile.Production
    ports:
      - '80:80'
    links:
      - server
    depends_on:
      - server
    volumes:
      - shared:/app

  mongo:
    image: mongo
    container_name: mongo
    environment:
      - TZ=Asia/Singapore
    ports:
      - '27017:27017'
    volumes:
      - shared:/data/db

  server:
    restart: always
    build:
      context: ./server
      dockerfile: Dockerfile.Production
    environment:
      - TZ=Asia/Singapore
    ports:
      - '5000:5000'
    links:
      - mongo
    volumes:
      - shared:/app
    expose:
      - 5000

  nginx:
    build: ./nginx
    environment:
      - TZ=Asia/Singapore
    links:
      - server
    depends_on:
      - server
      - client
    volumes:
      - shared:/app
    ports:
      - 8080:80

volumes:
  shared:

0 个答案:

没有答案