博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Docker-Nginx安装篇+配置挂载到宿主机
阅读量:3932 次
发布时间:2019-05-23

本文共 3410 字,大约阅读时间需要 11 分钟。

1.使用docker下载Nginx 镜像

#此处下载最新版docker pull nginx

2.挂载Nginx配置与静态目录

说明 :-p表示递归创建文件夹,这里挂载是为了后面配置Nginx方便,不创建挂载后面配置Nginx需要进入容器配置比较麻烦,所以挂载到宿主机

mkdir -p /data/nginx/{
conf,conf.d,html,logs}

3. 配置Nginx

创建 vim /data/nginx/conf/nginx.conf 配置文件

#user  nobody;worker_processes  1;#error_log  logs/error.log;#error_log  logs/error.log  notice;#error_log  logs/error.log  info;#pid        logs/nginx.pid;events {
worker_connections 1024;}http {
include 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 logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server {
listen 80; server_name localhost; #charset koi8-r; #access_log logs/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 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; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server {
# listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / {
# root html; # index index.html index.htm; # } #} # HTTPS server # #server {
# listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / {
# root html; # index index.html index.htm; # } #}}

配置index.html欢迎页

Welcome to nginx!

Welcome to nginx!

If you see this page, the nginx web server is successfully installed andworking. Further configuration is required.

For online documentation and support please refer tonginx.org.

Commercial support is available atnginx.com.

Thank you for using nginx.

4.启动Nginx镜像

分别挂载:

1.配置
2.静态资源目录
3.日志

docker run --name mynginx -d -p 80:80 -v /data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf  -v /data/nginx/html:/usr/share/nginx/html  -v /data/nginx/logs:/var/log/nginx -d docker.io/nginx

5.访问本机IP查看是否成功

注意:记得开启本机80端口,或者云服务器的80安全组

在这里插入图片描述

转载地址:http://cuqgn.baihongyu.com/

你可能感兴趣的文章
支付服务集成-支付宝
查看>>
使用openssl生成RSA公钥和私钥对
查看>>
Linux常用命令
查看>>
Linux 定时任务应用
查看>>
什么是线程安全
查看>>
第三方支付集成
查看>>
MySQL server has gone away 问题的解决方法
查看>>
常用链接
查看>>
Easyui Pagenation应用方法
查看>>
MySQL十大优化技巧
查看>>
MySQL数据库管理常用命令
查看>>
php 文件操作
查看>>
10个免费的PHP脚本资源下载网站推荐
查看>>
php正则表达式
查看>>
php自定义常量 define()函数
查看>>
PHP中文件读写操作
查看>>
PHP操作FTP-用法
查看>>
PHP面向对象v1:
查看>>
迭代开发优点
查看>>
php开发常识b_01
查看>>