如何使用Nginx在Docker容器上为Web应用提供服务 [英] How to use nginx to serve a web app on a Docker container

查看:67
本文介绍了如何使用Nginx在Docker容器上为Web应用提供服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个运行Ubuntu 18.04的网络服务器,该服务器当前为一个网站和两个博客服务.我还想在几个Docker容器上设置一个Ruby on Rails Web应用程序(这样我就可以部署到另一个非Linux服务器上).

I'm running a webserver running Ubuntu 18.04 that is currently serving a website and a couple of blogs. I'd also like to set up a Ruby on Rails web application on a couple of Docker containers (so I can possibly deploy to another non-Linux server).

我的服务器当前正在使用nginx为其托管的网站提供服务.如何使用相同的nginx安装在Docker容器中为Rails应用程序提供服务?我是否使用Rails应用程序的常规nginx设置,简单地在容器上公开端口3000并将nginx设置为侦听该端口?还是我需要做些其他事情?我不想将Nginx移至容器中-我只想使用当前的Nginx来为在容器中运行的应用程序提供服务.

My server is currently using nginx to serve the websites that it's hosting. How do I use the same nginx installation to serve a Rails application in a Docker container? Do I simply expose port 3000 on the container and set nginx to listen to that, using the normal nginx setup for a Rails app? Or is there something else I need to do? I don't want to move nginx to a container - I simply want to use my current nginx to serve an app running in a container.

推荐答案

您可以在/etc/nginx/conf.d/中创建包含以下内容的配置文件:

You can create config file in /etc/nginx/conf.d/ with content:

server {
    listen       *:80;
    server_name  <Your domain name>;

    location / {
        proxy_pass http://localhost:3000/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}

然后配置域名,将您的IP地址指向DNS提供程序.也许可以帮助您

and then config the domain name point your IP Address in DNS provider. Maybe it can help you

这篇关于如何使用Nginx在Docker容器上为Web应用提供服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆