Docker 简单搭建Nginx
2020-02-10 本文已影响0人
楚长铭
搭建环境
- Mac
拉取镜像
docker pull nginx
启动容器
docker run -d -p 20000:80 --name nginx-web -v /WorkSpace/dokcer/nginx/www:/usr/share/nginx/html -v /WorkSpace/dokcer/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /WorkSpace/dokcer/nginx/logs:/var/log/nginx nginx
- 端口20000指向nginx内部的的80端口
- 本地创建www,conf,logs三个文件夹,在conf文件夹下创建nginx.conf文件
配置文件
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
charset utf-8;
server{
listen 80;
server_name localhost;
location / {
proxy_pass http://ip:端口号;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
}
- 这样的效果就是访问localhost:20000就是访问http://ip:端口号这个地址
域名映射
server {
listen 80;
server_name test.com;
location / {
proxy_pass http://ip:端口号;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
- 域名映射与localhost相比就是改了server_name
- 但是本机需要配置host文件,mac是在 /etc文件夹下的host文件,在末尾添加
ip地址 www.test.com