Skip to content

docker 运行 nginx 的一些问题 #11

Description

@Kaviilee

先来一句碎碎念:但凡 windows 下的 nginx 好用一点我也不至于用 docker 来跑 nginx。

惯例先跑起来 nginx 容器,将本地的 nginx,conf 挂载进容器内

docker run -p 80:80 --name="nginx01" -v d:\tools\nginx-1.18.0\conf:/etc/nginx nginx

接下来就是修改本地的 nginx.conf

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  yourserver.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;

	    # with docker and proxy_pass should with http://
	    proxy_pass	http://192.168.100.120:3000;
	    # with local
	    # proxy_pass	http://localhost:3000;
			
        }
}

这里值得注意的就是 proxy_pass 的值,如果是本地跑 nginx,那么这个参数的值应该是 http://localhost:3000,但是在 docker 容器里面,那就应该设置为本机的 ip

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions