当前位置: 首页 > article >正文

阿里云轻量服务器docker部署nginx

  1. 拉取nginx docker镜像
sudo docker pull nginx
  1. 创建以下挂载目录及文件
用户目录下:conf  html  logs 
conf: conf.d nginx.conf
html: index.html
conf.d: default.conf
  1. nginx.conf添加文件内容
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;
}
  1. default.conf添加如下内容
server {
    listen       80;
    listen  [::]:80;
    server_name  localhost;

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

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}
  1. index.html添加内容
echo "Hello, Jason!" > ~/nginx/html/index.html
  1. 启动nginx服务,–network选项用于指定容器在启动时所连接的网络。Docker 提供了多种网络模式,每种模式适用于不同的场景。Docker 容器默认使用 桥接模式(Bridge Network)。桥接模式是 Docker 的默认网络模式,它会在宿主机上创建一个名为 docker0 的虚拟网桥,容器通过这个网桥与外部通信。指定HOST容器与宿主机共享同一个网络栈,容器直接使用宿主机的网络接口和 IP 地址。
sudo docker run -d --name nginx --network host -v ~/nginx/conf/nginx.conf:/etc/nginx/nginx.conf:ro -v ~/nginx/conf/conf.d:/etc/nginx/conf.d -v ~/nginx/logs:/var/log/nginx -v ~/nginx/html:/usr/share/nginx/html nginx
  1. 查看服务启动状态
sudo docker ps

http://www.kler.cn/a/545754.html

相关文章:

  • 【NPM 版本号控制完全指南:掌握依赖管理的核心艺术】
  • 如何在 IntelliJ IDEA 中使用 Bito AI 插件
  • Java 高频面试闯关秘籍
  • GPT 系列模型发展史:从 GPT 到 ChatGPT 的演进与技术细节
  • Linux 远程文件复制传输-----scp/rsync/sftp
  • GD32 ADC 工作模式及应用详解
  • JVM——垃圾回收算法
  • js实现异步的方法
  • Vue3(2)
  • 责任链模式——C++实现
  • Kernel之Tcpdump和Netfilter
  • Node.js中的模块化:从原理到实践
  • 云原生AI Agent应用安全防护方案最佳实践(下)
  • 【安全测试】0基础新手学Web安全测试笔记(一)
  • ffmpeg --protocols
  • 【Android】设计一个圆角矩形的WebView
  • (2025)深度分析DeepSeek-R1开源的6种蒸馏模型之间的逻辑处理和编写代码能力区别以及配置要求,并与ChatGPT进行对比(附本地部署教程)
  • vue项目使用vite和vue-router实现history路由模式空白页以及404问题
  • 5、pod 详解 (kubernetes)
  • 【博客之星】GIS老矣尚能饭否?WebGIS项目实战经验与成果展示