当前位置: 首页 > 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.lryc.cn/news/536783.html

相关文章:

  • (萌新入门)如何从起步阶段开始学习STM32 —— 我应该学习HAL库还是寄存器库?
  • Windchill开发-电子仓相关对象信息查询SQL
  • MySQL 数据库定时任务及进阶学习
  • DeepSeek教unity------MessagePack-01
  • 知识拓展:Python序列化模块 marshal 模块详解
  • leetcode 2684. 矩阵中移动的最大次数
  • 机械学习基础-6.更多分类-数据建模与机械智能课程自留
  • 自动化测试实战
  • qt QPlainTextEdit总结
  • AWS SES 邮件服务退信/投诉处理与最佳实践指南
  • 理解WebGPU 中的 GPUAdapter :连接浏览器与 GPU 的桥梁
  • rpx和px混用方案
  • 光伏设计软件分类:无人机、Unity3D引擎齐上阵
  • 太速科技-616-基于6U VPX XCVU9P+XCZU7EV的双FMC信号处理板卡
  • 国产鲲鹏920+欧拉+达梦
  • LeetCode--146. LRU 缓存【Golang中的list】
  • 查看notebook的jupyter token
  • vue+springboot+webtrc+websocket实现双人音视频通话会议
  • 什么是高亮环形光源
  • 2025年3月一区SCI-混沌进化优化算法Chaotic evolution optimization-附Matlab免费代码
  • 51单片机俄罗斯方块开机动画
  • RK3588开发板部署DeepSeek-R1-Distill-Qwen-1.5B的步骤及问题
  • 网络安全 | 安全信息与事件管理(SIEM)系统的选型与实施
  • DeepSeek接口联调(postman版)
  • RadASM环境,win32汇编入门教程之三
  • oracle多次密码错误登录,用户锁住或失效
  • HCIA-Datacom笔记3:网络工程
  • [NGINX]命令行参数
  • http 模块
  • 本地部署DeepSeek + AnythingLLM 搭建高效安全的个人知识库