我有一个使用pyramida / graphql的后端服务。后端正在端口4001上运行。
这是我的Nginx配置文件<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/select2@4.0.13/dist/css/select2.min.css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/npm/select2@4.0.13/dist/js/select2.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
<select v-model="formData.allowance_id" id="allowance_id" name="allowance_id" class="form-control select2" required @input="alert('Test')">
<option :key="'allowance_id'" value="">choose allowance</option>
<option v-for="(allowance, index) in allowances" :key="allowance.id" :value="allowance.id">
@{{ allowance.name }}
</option>
</select>
<div>
<strong>Selected: </strong> {{formData.allowance_id}}
</div>
<div>
<button type="button" @click="onSubmit">Submit</button>
</div>
</div>
当我从服务器运行它时,它既可以在proxy_pass:http://$host:4001
和http://server:4001
上运行
但是,当我从本地主机运行它时,出现以下错误:
http://server
什么原因导致此错误以及如何解决?
docker-compose:
no resolver defined to resolve localhost, client: 172.30.0.1, server: _, request: "GET / HTTP/1.1", host: "localhost"
nginx配置:
backend:
image: base
command: >
sh -c "npm run deploy && npm run start"
env_file: ${ENV_FILE}
ports:
- '4001:4001'
depends_on:
- prisma
restart: always
volumes:
- ./deploy/certs:/deploy/certs
nginx:
image: nginx:latest
volumes:
- ./deploy/certs:/deploy/certs
- ./deploy/nginx/conf.d:/etc/nginx/conf.d
ports:
- 80:80/tcp
- 443:443/tcp
depends_on:
- backend
restart: always
env_file: ${ENV_FILE}
答案 0 :(得分:0)
我想您需要连接到backend
文件中docker-compose.yml
中指定的nginx.conf
服务。
例如
upstream localhost {
server backend:4001;
}
server {
listen 80;
server_name localhost;
}
您可以尝试这个吗?