首页 > 系统相关 >Docker安装Nginx

Docker安装Nginx

时间:2024-10-10 17:00:10浏览次数:1  
标签:index log nginx Nginx html conf Docker 安装 docker

1.下载镜像文件

docker pull nginx

2.创建挂载目录

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

3.创建nginx.conf配置文件

路径为:/docker/nginx/conf/nginx.conf

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


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;
}

4.创建 default.conf文件

路径为:/docker/nginx/conf.d/default.conf

server {  
    listen       80;  
    server_name  localhost;  
  
    #charset koi8-r;  
    #access_log  /var/log/nginx/log/host.access.log  main;  
  
    location / {  
        #root   /data/nginx/html;  
        root   /usr/share/nginx/html;  
        index  index.html index.htm;  
        #autoindex  on;  
        #try_files $uri /index/index/page.html;  
        #try_files $uri /index/map/page.html;  
    }  
  
    #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;  
    #}  
}

5.创建一个简易的Html文件


#路径为:/docker/nginx/html/index.html
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>系统时间</title>
</head>
<body>
<div id="datetime">
    <script>
        setInterval("document.getElementById('datetime').innerHTML=new Date().toLocaleString();", 1000);
    </script>
</div>
</body>

6.启动容器

# 外部81端口映射到容器内部80端口
docker run --name nginx81 -d -p 81:80 -v /docker/nginx/html:/usr/share/nginx/html -v /docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf  -v /docker/nginx/logs:/var/log/nginx -v /docker/nginx/conf.d:/etc/nginx/conf.d -d nginx:latest

标签:index,log,nginx,Nginx,html,conf,Docker,安装,docker
From: https://www.cnblogs.com/shangjianan/p/18456705

相关文章

  • AWS Linux2 安装 nginx
    如果您使用的是AWSLinux2,则必须从AWS“ExtrasRepository”安装 nginx。要查看可用包的列表:#Viewlistofpackagestoinstallamazon-linux-extraslist您会看到类似于以下内容的列表:0ansible2disabled[=2.4.2]1emacsdisabled[=25.3]2memcached1......
  • 【Ubuntu】在Ubuntu上安装IDEA
    【Ubuntu】在Ubuntu上安装IDEA零、前言最近换了Ubuntu系统,但是还得是要写代码,这样就不可避免地用到IDEA,接下来介绍一下如何在Ubuntu上安装IDEA。壹、下载这一步应该很容易的,直接打开IDEA的下载页面,点击下载即可开始下载:https://www.jetbrains.com.cn/idea/download/?section=l......
  • 提升网站响应速度与可靠性:Nginx负载均衡最佳实践 转载
    负载均衡配置作为代理服务器,一般都需要向上游服务器的集群转发请求。这里的负载均衡是指选择一种策略,尽量把请求平均地分布到每一台上游服务器上。1.1upstream块语法:upstreamname{...}配置块:httpupstream块定义了一个上游服务器的集群,便于反向代理中的proxy_pa......
  • Docker:更改Docker默认IP网段
    问题  今天部署服务时遇到一个问题:内网网段都是互通的,但是我的这台服务器(16网段)访问不到(17网段)的系统服务,使用宿主机ping命令也是失败的,但是其他同网段服务器(16网段)是可以访问到(17网段)服务的,后来经过排查,发现docker启动的默认网段与17网段冲突,导致访问不到指定服务。解决......
  • 记录一次本地安装AI ollama大模型数据对话 的经历
    浏览器打开 Ollama官网  下载对应的版本,我这里下载的 是对应 windows的版本,下载后直接运行安装安装完成后 打开 dos控制台,win+r,cmd那个,输入ollama 如果显示如下截图内容,就说明安装成功了,接下来就是下载 具体的 大数据库了  安装大模型前,建议先修......
  • 安装了sqlite3依赖,编译源码报No package 'sqlite3' found
    如果已经安装了SQLite3.44.0,但在运行./configure时仍然出现“Nopackage'sqlite3'found”的错误,这通常是因为pkg-config没有找到相应的SQLite开发文件(.pc文件)。可按照以下步骤检查和修复此问题:1.确保pkg-config已安装首先,确认系统上安装了pkg-config工具:sudoyuminstall......
  • arm imx6ull docker启动失败问题查找与解决 内核配置相关
    1、增加POSIXMessageqeue:couldnotgetinitialnamespace:nosuchfileordirectory CONFIG_POSIX_MQUEUE=y2、增加namespacefailedtosettoinitialnamespaceCONFIG_NAMESPACES=y3、创建网络失败,veth配置:dockercreateendpointquirky_shternonnetworkbridge......
  • 安装 Anaconda、PyTorch(GPU 版)库与 PyCharm
    Anaconda是一款巨大的Python环境集成平台,里面包含了Python解释器、JupyterNotebook代码编辑器以及很多的第三方库,所以安装Anaconda后我们无需再安装Python解释器,非常方便。一、安装Anaconda1.卸载Anaconda(可选)如果我们原来的电脑上安装过Anaconda,为了避免重复安......
  • Oracle-19g数据库的安装
    简介Oracle是一家全球领先的数据库和云解决方案提供商。他们提供了一套完整的技术和产品,包括数据库管理系统、企业级应用程序、人工智能和机器学习工具等。Oracle的数据库管理系统是业界最受欢迎和广泛使用的数据库之一,它可以管理和存储大量结构化和非结构化数据,并支持高度可......
  • Unbuntu nginx 安装
    1.下载源码下载页面:https://nginx.org/en/download.html下载地址:https://nginx.org/download/nginx-1.27.2.tar.gzcurl-Ohttps://nginx.org/download/nginx-1.27.2.tar.gz2.依赖配置sudoaptinstallgccmakelibpcre3-devzlib1g-devopenssllibssl-dev3.编译解压......