zoukankan      html  css  js  c++  java
  • nginx安装

     

    第1章 nginx_web服务安装

    1.1 进行nginx软件下载

    命令:cd /install

    命令:wget http://nginx.org/download/nginx-1.12.2.tar.gz

    1.2 安装依赖软件

    命令:yum install -y pcre-devel openssl-devel

    1.3 解压软件,创建虚拟用户,进行编译安装

    命令:(解压)tar xf nginx-1.12.2.tar.gz

    命令:(检查)ll /server/tools

    drwxr-xr-x 8 1001 1001 4096 Oct 17 21:16 nginx-1.12.2

    -rw-r--r-- 1 root root 981687 Oct 17 21:20 nginx-1.12.2.tar.gz

    命令:(切换)cd nginx-1.12.2/

    命令:(查看路径)pwd

    /install/nginx-1.12.2

    命令:(创建虚拟管理用户)useradd -s /sbin/nologin -M nginx

    命令:(创建)nginx命令安装的所在地

    命令:(创建)mkdir -p /opt/nginx-1.12.2/

    编译:进行配置(/install/nginx-1.12.2)

    命令:./configure --prefix=/opt/nginx-1.12.2 --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module

    ###配置参数说明:

    --prefix=PATH set installation prefix

    指定软件程序安装的路径信息

    --user=USER set non-privileged user for worker processes

    创建一个虚拟用户,用于管理nginx服务的worker进程

    --group=GROUP set non-privileged group for worker processes

    创建一个虚拟用户组,用于管理nginx服务的worker进程

    --with-http_ssl_module enable ngx_http_ssl_module

    让nginx服务可以支持https访问

    --with-http_stub_status_module enable ngx_http_stub_status_module

    便于监控软件监视nginx服务运行状态

    1.4 编译

    说明:编译过程实质是将各种程序语言转换为系统可以识别的二进制信息

    命令:(把代码---->二进制)make

    1.5 编译安装

    命令:(安装)make install

    1.6 创建程序目录软链接文件

    命令:(创建软连接)cd /opt/ && ln -s /opt/nginx-1.12.2/ /opt/nginx

    命令:(检查)ll /opt/

    total 4

    lrwxrwxrwx 1 root root 26 Feb 2 17:14 nginx -> /opt/nginx-1.12.2/

    drwxr-xr-x 6 root root 4096 Feb 2 17:13 nginx-1.12.2

    1.7 网站服务启动成功

    命令:(启动nginx服务)/opt/nginx/sbin/nginx     

    1.8 检查测试

    命令:(检查进程是否开启)ps -ef |grep nginx

    root 6948 1 0 17:17 ? 00:00:00 nginx: master process /opt/nginx/sbin/nginx

    www 6949 6948 0 17:17 ? 00:00:00 nginx: worker process

    root 6951 1279 0 17:17 pts/1 00:00:00 grep nginx   

    说明:master进程表示nginx主进程,负责nginx服务的启动 停止等操作

    worker进程表示真正处理用户请求的进程

    命令:(检查80端口是否开启)netstat -lntup|grep nginx

    tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 12684/nginx

    检查nginx软件是否安装成功

    windows  39.96.209.11

    1.9 欢迎使用nginx的界面

     

    1.10 初始化nginx配置文件:

    命令:cd  /opt/nginx/conf    

    #进行nginx的配置文件的备份

    命令:(备份)cp nginx.conf{,.bak}

    命令:vim nginx.conf (配置nginx的配置文件的主配置文件)

    配置文件内容(如下:)

    =============================================================================

    worker_processes 1;

      events {

        worker_connections 1024;

      }

      http {

        include mime.types;

        default_type opt/octet-stream;

        sendfile on;

        keepalive_timeout 65;

      server {

        listen 80;

        server_name www.huchangxi.com;

        root html/huchangxi;

        index index.html index.htm;

      }

    }

    =============================================================================

    1.11 创建网站目录和文件:

    命令:mkdir /opt/nginx/html/huchangxi/ -p

    命令:echo "39.96.209.111" > /opt/nginx/html/huchangxi/index.html

    命令:cat /opt/nginx/html/huchangxi/index.html

    39.96.209.111

    1.12 服务重启

    #检查语法

    /application/nginx/sbin/nginx -t

    nginx: the configuration file /opt /nginx-1.12.2/conf/nginx.conf syntax is ok

    nginx: configuration file /opt/nginx-1.12.2/conf/nginx.conf test is successful

    /opt/nginx/sbin/nginx 启动

    1.13 浏览器进行访问测试

    #需要对虚拟主机域名进行解析(编写hosts文件-linux/ windows里面hosts)

    添加www的解析

    命令:(添加)vim /etc/hosts

    39.96.209.111 nginx

    1.14 设置开机自启nginx服务

    #把启动nginx的命令添加到/etc/rc.local开启自启动里

    命令: vim /etc/rc.local

    /application/nginx/sbin/nginx

  • 相关阅读:
    Linux rcp命令详解
    Linux patch命令详解
    Linux paste命令详解
    linux od命令详解
    linux mv命令详解
    Linux more命令详解
    Linux mktemp命令
    MySQL状态变量详解
    mysql性能分析show profile/show profiles
    MySQL执行计划
  • 原文地址:https://www.cnblogs.com/A121/p/10559020.html
Copyright © 2011-2022 走看看