docker 安装nginx 配置端口转发
2024
加载磁盘
lsblk
mount /dev/xx  /home/xx
nginx配置证书
docker run --name nginx2 -d -p 80:80  -p 443:443  -v /home/server/nginx/conf/nginx.conf:/etc/nginx/nginx.conf  -v /home/nginx/log:/var/log/nginx  -v /home/server/nginx/html:/usr/share/nginx/html    -v  /home/server/nginx/xiaojava.fun_bundle.crt:/etc/nginx/xiaojava.fun_bundle.crt  -v /home/server/nginx/xiaojava.fun.key:/etc/nginx/xiaojava.fun.key nginx
docker 拉取镜像
docker run --name nginx -d -p 80:80   -v /home/xiaoqi/nginx/conf/nginx.conf:/etc/nginx/nginx.conf  -v /home/xiaoqi/nginx/log:/var/log/nginx  -v /home/xiaoqi/nginx/html:/usr/share/nginx/html nginx
or
docker  run --restart=always  --name nginx -d -p 80:80   nginx
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;
}
修改nginx.conf 文件
在http{}里添加如下信息, 进行端口转发
server {
        listen       80;
        server_name  42.192.251.34;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {
            proxy_pass   http://42.192.251.34:8090/;
        }
}
完整nginx配置
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;
        server_name  www.xdjava.top;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        
        location / {
            proxy_pass   http://42.192.251.34:8090/;
         }
       }
server {
        listen        8000;
        server_name   42.192.251.34;
        location / {
            proxy_pass http://42.192.251.34:8090/;
         }
        }
}
        版权声明:
        本站所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 
              晓!
      
    喜欢就支持一下吧
      