您的位置:首页 > 运维架构 > Nginx

Nginx使用、安装、启动、常用命令

2018-12-04 10:39 555 查看

【轻量级】 Nginx 的web服务器

测试服务器阿里云 香港 可用区C
47.89.12.182
1 vCPU 2 GB (I/O优化)
ecs.n4.small 1Mbps
轻量级 149.129.101.114

安装流程

下载地址

【官网下载】 【中文文档】

下载好后存到单独的目录

mv nginx-1.15.7 /usr/local/nginx

把下载文件下载到src中并解压

wget http:网址 -P /usr/src

连接下载

  1. mac终端链接服务器并下载

    ssh -l root IP

    如果ssh连不了,清空下ip

    vi ~/.ssh/known_hosts

    常用命令:

      hostname
      查看服务器名
    • ifconfig
      查看服务器ip
    • wget http:网址 -P /usr/src
      下载网络资源,这里放到/usr/src
    • yum -y install 命令名
      添加下载命令
    • du -h 文件名
      查看文件具体信息
    • /sbin/nginx -g ../conf/nginx.conf
      检查修改conf是否正确
    • killall -s HUP nginx
      立即重新加载配置文件

安装的前戏

  1. tar xf 文件名
    解压压缩包

  2. cd进目录解压好的目录中

  3. yum -y install gcc pcre-devel zlib zlib-devel
    安装必要命令工具(gcc编译器 pcre重写功能 zlib解压工具)

  4. 指定软件安装路径

    ./configure --prefix=/usr/local/nginx

如果出现error 就必须要解决否则后面无辜出错

编译

make
使用gcc将源码生成可执行程序

如果出现error 就必须要解决否则后面无辜出错

安装

make install

目录归类

  • 安装目录
    :nginx path prefix: “/usr/local/nginx”
  • 启动文件
    :nginx binary file: “/usr/local/nginx/sbin/nginx”
  • 模块
    :nginx modules path: “/usr/local/nginx/modules”
  • 配置文件目录
    :nginx configuration prefix: “/usr/local/nginx/conf”
  • pid进程记录文件
    :nginx configuration file: “/usr/local/nginx/conf/nginx.conf” nginx pid file: “/usr/local/nginx/logs/nginx.pid”
  • 错误日志
    :nginx error log file: “/usr/local/nginx/logs/error.log”
  • 访问日志
    :nginx http access log file: “/usr/local/nginx/logs/access.log”

启动

  1. 验证端口是否占用

    lsof -i :80
    或查看端口占用
    netstat -ntpl

  2. 启动

    /usr/local/nginx/sbin/nginx
    指定路径启动

  3. 验证是否启动:直接访问网址

    或者用elinks 文本浏览器(不会有缓存更真实)
    没有的话就安装

    yum -y install elinks

    访问:
    elinks http://ip --dump

查看ningx 日志查看

阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐