我需要使用dotnet core和nginx代理服务器。我有两个简单的图像和docker撰写文件。 Dotnet应用程序适用于正确的端口。但是当我和nginx一起使用时,我认为是80的地图。 Nginx抛出错误502。
我的步骤:
这是我的app langsettings:
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://*:5000/",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express (Production)": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Production"
}
}
}
}
App Docker文件:
# FROM microsoft/dotnet:latest
FROM microsoft/aspnetcore-build
#Update everytihing
RUN apt-get -qq update && apt-get -qq -y install bzip2
#remove force apt lists
RUN rm -rf /var/lib/apt/lists/*
#for secure, copy to app folder
COPY . /app
RUN rm -Rf /app/node_modules
RUN rm -Rf /app/bower_components
#set workdir
WORKDIR /app
#set ASPNETCORE_ENVIRONMENT to Production
ENV ASPNETCORE_ENVIRONMENT "Production"
#restore packages
RUN ["dotnet", "restore"]
#build c#
RUN ["dotnet", "build"]
#npm install dependencies (webpack etc.)
RUN ["npm", "install"]
#run npm task webpack-prod
RUN ["npm", "run", "webpack-prod"]
EXPOSE 5000/tcp
# command to run
CMD ["dotnet", "run", "--server.urls", "http://*:5000"]
搬运工-compose.yml
version: '2'
services:
nginx-proxy:
image: jwilder/nginx-proxy
container_name: nginx-proxy
ports:
- "80:80"
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
mujcykloweb:
image: mujcykloweb
container_name: mujcyklowebcontainer
environment:
- VIRTUAL_HOST=localhost
当你运行时: docker-compose up 并转到 http://localhost
Creating network "cykloweb_default" with the default driver
Creating nginx-proxy
Creating mujcyklowebcontainer
Attaching to mujcyklowebcontainer, nginx-proxy
nginx-proxy | forego | starting nginx.1 on port 5000
nginx-proxy | forego | starting dockergen.1 on port 5100
nginx-proxy | dockergen.1 | 2017/01/14 16:16:36 Generated '/etc/nginx/conf.d/default.conf' from 2 containers
nginx-proxy | dockergen.1 | 2017/01/14 16:16:36 Running 'nginx -s reload'
nginx-proxy | dockergen.1 | 2017/01/14 16:16:36 Watching docker events
nginx-proxy | dockergen.1 | 2017/01/14 16:16:36 Contents of /etc/nginx/conf.d/default.conf did not change. Skipping notification 'nginx -s reload'
mujcyklowebcontainer | Project app (.NETCoreApp,Version=v1.0) was previously compiled. Skipping compilation.
mujcyklowebcontainer | Running Environment: Production
mujcyklowebcontainer | info: Microsoft.Extensions.DependencyInjection.DataProtectionServices[0]
mujcyklowebcontainer | User profile is available. Using '/root/.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest.
mujcyklowebcontainer | Hosting environment: Production
mujcyklowebcontainer | Content root path: /app
mujcyklowebcontainer | Now listening on: http://+:80
mujcyklowebcontainer | Application started. Press Ctrl+C to shut down.
nginx-proxy | nginx.1 | 2017/01/14 16:16:58 [error] 25#25: *1 no live upstreams while connecting to upstream, client: 172.19.0.1, server: localhost, request: "GET / HTTP/1.1", upstream: "http://334389048b872a533002b34d73f8c29fd09efc50/", host: "localhost:5050"
nginx-proxy | nginx.1 | localhost 172.19.0.1 - - [14/Jan/2017:16:16:58 +0000] "GET / HTTP/1.1" 502 575 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36"
nginx-proxy | nginx.1 | localhost 172.19.0.1 - - [14/Jan/2017:16:16:58 +0000] "GET /favicon.ico HTTP/1.1" 502 575 "http://localhost:5050/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36"
nginx-proxy | nginx.1 | 2017/01/14 16:16:58 [error] 25#25: *1 no live upstreams while connecting to upstream, client: 172.19.0.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", upstream: "http://334389048b872a533002b34d73f8c29fd09efc50/favicon.ico", host: "localhost:5050", referrer: "http://localhost:5050/"
nginx-proxy | nginx.1 | 2017/01/14 16:17:32 [error] 25#25: *1 no live upstreams while connecting to upstream, client: 172.19.0.1, server: localhost, request: "GET / HTTP/1.1", upstream: "http://334389048b872a533002b34d73f8c29fd09efc50/", host: "localhost:5050"
nginx-proxy | nginx.1 | localhost 172.19.0.1 - - [14/Jan/2017:16:17:32 +0000] "GET / HTTP/1.1" 502 575 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36"
nginx-proxy | nginx.1 | 2017/01/14 16:17:32 [error] 25#25: *1 no live upstreams while connecting to upstream, client: 172.19.0.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", upstream: "http://334389048b872a533002b34d73f8c29fd09efc50/favicon.ico", host: "localhost:5050", referrer: "http://localhost:5050/"
nginx-proxy | nginx.1 | localhost 172.19.0.1 - - [14/Jan/2017:16:17:32 +0000] "GET /favicon.ico HTTP/1.1" 502 575 "http://localhost:5050/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36"
我认为,该网络应用程序有错误的端口映射,因为80应该有nginx吗? (现在听取:http://+:80)
我尝试 docker composive --force-recreate ,停止/启动docker并重新启动pc,但同样的问题。
请问哪里有问题? 谢谢你的时间。