windows使用docker安装nginx

184 阅读1分钟

windows直接下载nginx安装包也可以,进入cmd开启nginx,但是有时关闭不了需要重启电脑,就比较麻烦

所以使用docker安装就比较方便

查了很多教程还是比较坑的,直接在需要的地方新建html,conf文件夹,然后在cmd输入命令

image.png

//开启80端口,将html还有nginx.conf配置文件映射到e盘
docker run --name nginx -d -p 80:80 -v E:\docker-Nginx\html:/usr/share/nginx/html -v E:\docker-Nginx\conf\nginx.conf:/etc/nginx/nginx.conf nginx

然后在conf里面修改配置文件

user nginx;
worker_processes auto;

error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;


events {
    worker_connections 1024;
}


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

    log_format main '$remote_addr - $remote_user [$time_local] "$request" '
    '$status $body_bytes_sent "$http_referer" '
    '"$http_user_agent" "$http_x_forwarded_for"';

    access_log /var/log/nginx/access.log main;

    sendfile on;
    #tcp_nopush     on;

    keepalive_timeout 65;

    #gzip  on;

    #include /etc/nginx/conf.d/*.conf;
    server {
        listen 80;
        listen [::]:80;
        server_name localhost;

        location / {
            root /usr/share/nginx/html;
            index index.html index.htm;
            try_files $uri $uri/ /index.html;
        }
        location /api/ {
            proxy_pass http://192.168.1.134:8080;
        }
    }
}