欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 科技 > IT业 > 阿里云轻量服务器docker部署nginx

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

2025/2/26 3:42:49 来源:https://blog.csdn.net/dolly_baby/article/details/145616439  浏览:    关键词:阿里云轻量服务器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

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词