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

阿里云轻量服务器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.dtcms.com/a/13760.html

相关文章:

  • windows,docker停止所有容器
  • TDengine 性能测试工具 taosBenchmark
  • 基于RTOS的STM32游戏机
  • electron.vite 项目创建以及better-sqlite3数据库使用
  • MySQL数据库入门到大蛇尚硅谷宋红康老师笔记 基础篇 part 11
  • 计算机毕业设计SpringBoot+Vue.js飞机票在线订购系统(源码+文档+运行视频+讲解视频)
  • 清华大学:DeepSeek 如何赋能职场应用(35 页 PDF)
  • deepseek与gpt,核心原理对比
  • python C# 内存共享互传 图像 以及字符串
  • 【CXX】2 CXX blobstore客户端说明
  • 链表 —— 常用技巧与操作总结详解
  • Android studio常量表达式的错误
  • 分布式服务框架 如何设计一个更合理的协议
  • Python分享20个Excel自动化脚本
  • 作业。。。。。
  • 在vivado中对数据进行延时,时序对齐问题上的理清
  • 蓝桥杯 Java B 组之枚举算法(暴力破解)
  • AI赋能创业:ScriptEcho如何助力快速搭建前端应用
  • joint_info.npz 找不到
  • mapbox 从入门到精通 - 目录
  • 基于python sanic框架,使用Nacos进行微服务管理
  • 苹果公司宣布正式开源 Xcode 引擎 Swift Build145
  • MySQL的innoDB引擎
  • Mac之JDK安装
  • Pyqt6 中 QMediaPlayer 音视频播放
  • DeepSeek免费部署到WPS或Office
  • 鸿蒙面试题
  • Kotlin 扩展函数与内联函数
  • python视频爬虫
  • 2025 年 2 月 TIOBE 指数