一. 非docker 方式部署 nginx 请参考:
https://www.runoob.com/linux/nginx-install-setup.html
二. docker 方式部署nginx
1. 使用docker运行nginx
# home/docker/nginx/www 等地址均为宿主文件夹映射
docker run -d -p 80:80 -p 443:443 --name nginx-web --restart always \
-v /home/docker/nginx/www:/usr/share/nginx/html \
-v /home/docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /home/docker/nginx/conf/ssl:/etc/nginx/ssl \
-v /home/docker/nginx/conf/vhost:/etc/nginx/vhost \
-v /home/docker/nginx/logs:/var/log/nginx nginx
#刷新配置
docker exec -it nginx-web service nginx reload
2. 切换到 /home/docker/nginx
/home/docker/nginx
3. conf 配置,如果没有文件夹自己创建
4. nginx.conf 内容,复制粘贴即可,所有域名映射均转移到了vhost文件夹
#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;
#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 logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
include vhost/*.conf;
}
5. vhost 文件夹内容
server {
listen 80;
server_name gitea.xxxxx.com;
location / {
proxy_pass http://172.18.0.4:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
刷新配置后生效
#刷新配置
docker exec -it nginx-web service nginx reload