反向代理位置到Docker容器

时间:2018-08-07 12:53:49

标签: nginx reverse-proxy proxypass

我需要将请愿书从www.domain.codomain.co重定向到nginx服务器(当前有效),必须强制执行https(当前有效)。

我确实需要将domain.com/location_a/www.domain.com/location_a/重定向到Docker容器(部分工作)。

这是我的站点nginx配置:

upstream blog_container {
    server localhost:88;
}

server {

        root /var/www/domain.co/html/;
        index index.html index.htm index.nginx-debian.html;

        server_name domain.co www.domain.co;

        location / {
                try_files $uri $uri/ =404;
        }

        location ^~ /blog {
                 proxy_pass http://blog_container;
                 proxy_redirect     off;
                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_set_header   X-Forwarded-Host $server_name;
                #try_files $uri $uri/ =404;
        }

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/domain.co/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/domain.co/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot


}server {
    if ($host = www.domain.co) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = domain.co) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        listen 80;
        listen [::]:80;

        server_name domain.co www.domain.co;
    return 404; # managed by Certbot
}

实际上,如果我正在访问domain.co容器,并且正在显示容器根目录上的html(但仅显示容器的根目录,则不会显示所有资源,例如css,img和js,它们未映射)。

如何代理/blog/ 以及嵌套的位置和资源到容器?

1 个答案:

答案 0 :(得分:-1)

示例配置文件;

   server {
    listen       80;
    server_name  demo.com;
    return 301 http://www.$host$request_uri; ## HERE
   }
   server {
    listen       80;
    server_name www.demo.com;
    root         /usr/share/nginx/html;
    location / {
    }

}