栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

Nginx 安装与使用

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Nginx 安装与使用

前言

Nginx (engine x) 是一个高性能的HTTP和反向代理web服务器,同时也提供了IMAP/POP3/SMTP服务。本文介绍如何在docker下部署nginx。

Nginx Docker拉取、配置、启动。 准备docker镜像

拉取nginx docker

 docker pull nginx
 docker  images 
配置nginx 创建配置目录:
 mkdir -p /opt/nginx/config/conf.d
 mkdir -p /opt/nginx/logs
 mkdir -p /opt/nginx/www
创建配置
  • 在/opt/nginx/config下创建 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;
}
  • 在 /opt/nginx/config/conf.d 目录下创建 default.conf 配置:
 server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #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;
    #}
}
启动

docker启动命令:

 docker run 
    --name {nginxInstance} 
    -p 80:80 
    -v  /opt/nginx/config/nginx.conf:/etc/nginx/nginx.conf 
    -v /opt/nginx/config/conf.d:/etc/nginx/conf.d  
    -v /opt/nginx/logs:/var/log/nginx 
    -v /opt/nginx/www:/usr/share/nginx 
    -d {镜像名:版本}

{nginxInstance} :Nginx实例名
{镜像名}:一般拉取最新镜像直接换成nginx就行

验证
  • 在 /opt/nginx/www/html 放入index.html, 否则汇报404
  • 访问 http://localhost 会显示 index.html 页面
  • 如果远程服务器,访问不了的话,检查telnet ip port 看看是否通
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/941590.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号