1.nginx
1.转发请求图
2.宿主机nginx
server {
    listen       80;
    server_name  localhost;
    #charset koi8-r;
    #access_log  logs/host.access.log  main;
    location / {
        root   html;
        index  index.html index.htm;
        # deny  xxx.xxx.xxx.xxx;
        # allow  192.168.1.0/24;
    }
    #error_page  404              /404.html;
    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}
    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
    location /test {
        proxy_pass  http://127.0.0.1:6666/; #最后如果没有反斜杠,那么转发请求是http://127.0.0.1:6666/test, 如果最后有反斜杠,那么转发请求就是http://127.0.0.1:6666/
    }
}
3. docker开启
docker container run \ -d \ -p 6666:80 \ --rm \ --name mynginx \ nginx:1.14
4.测试
浏览器中输入http://主机IP/ ------> 访问的是宿主主机的nginx
浏览器中输入http://主机IP/test ------> 访问的是宿主主机转发给docker中的nginx
5.备注:
需要注意nginx中root(相对路径,路径的拼接)和alias(绝对路径)的区别,同时需要注意配置文件中代理的反斜杠有无的区别
    http://www.cnblogs.com/makexu/

 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号