Linux ( Centos 7.3 x64) 安装 nginx (一)

安装环境所需插件

 1、 安装gcc    GCC(GNU Compiler Collection,GNU编译器套件)是由GNU开发的编程语言译器。GNU编译器套件包括C、C++、 Objective-C、 Fortran、Java、Ada和Go语言前端,也包括了这些语言的库(如libstdc++,libgcj等。)

gcc -v

yum install -y gcc

 2、安装 PCRE   PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括 perl 兼容的正则表达式库。这些在执行正规表达式模式匹配时用与Perl 5同样的语法和语义是很有用的

rpm -qa | grep pcre

yum install -y pcre pcre-devel

3、安装 zlib zlib是提供数据压缩用的函式库, 提供了很多种压缩和解压缩方式 nginx使用zlib对http包的内容进行gzip,所以需要安装

yum list | grep zlib*

yum install -y zlib zlib-devel

4、安装OpenSSL  OpenSSL是一个开放源代码的软件库包,应用程序可以使用这个包来进行安全通信,避免窃听,同时确认另一端连接者的身份。这个包广泛被应用在互联网的网页服务器上。

yum install -y openssl openssl-devel

安装Nginx

  1、下载 Nginx 安装包  (地址可以去您Nginx官网获取)

wget http://nginx.org/download/nginx-1.16.1.tar.gz

  2、创建 文件夹

cd /usr/local

mkdir nginx

  3、解压文件到nginx目录

cd /

tar -zxvf nginx-1.16.1.tar.gz -C /usr/local/nginx/

  4、 切换到nginx目录

pwd

cd /usr/local/nginx/

ll

  5. 安装nginx (注意在nginx目录下执行)

./configure

make

make install

  6、配置nginx.conf

路径 : /usr/local/nginx/conf/nginx.conf

  7、启动nginx

./nginx

  8、 查看启动成功没有

ps -ef | grep nginx

说明

nginx.conf

#user  nobody;
worker_processes  1; #工作进程:数目。根据硬件调整,通常等于cpu数量或者2倍cpu数量。
 
#错误日志存放路径
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
 
#pid        logs/nginx.pid; # nginx进程pid存放路径
 
 
events {
    worker_connections  1024; # 工作进程的最大连接数量
}
 
 
http {
    include       mime.types; #指定mime类型,由mime.type来定义
    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; #用log_format指令设置日志格式后,需要用access_log来指定日志文件存放路径
                    
    sendfile        on; #指定nginx是否调用sendfile函数来输出文件,对于普通应用,必须设置on。
            如果用来进行下载等应用磁盘io重负载应用,可设着off,以平衡磁盘与网络io处理速度,降低系统uptime。
    #tcp_nopush     on; #此选项允许或禁止使用socket的TCP_CORK的选项,此选项仅在sendfile的时候使用
 
    #keepalive_timeout  0;  #keepalive超时时间
    keepalive_timeout  65;
 
    #gzip  on; #开启gzip压缩服务
 
    #虚拟主机
    server {
        listen       80;  #配置监听端口号
        server_name  localhost; #配置访问域名,域名可以有多个,用空格隔开
 
        #charset koi8-r; #字符集设置
 
        #access_log  logs/host.access.log  main;
 
        location / {
            root   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$ { #请求的url过滤,正则匹配,~为区分大小写,~*为不区分大小写。
        #    root           html; #根目录
        #    fastcgi_pass   127.0.0.1:9000; #请求转向定义的服务器列表
        #    fastcgi_index  index.php; # 如果请求的Fastcgi_index URI是以 / 结束的, 该指令设置的文件会被附加到URI的后面并保存在变量$fastcig_script_name中
        #    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; # ssl_prefer_server_ciphers  on; #
 
 
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
 
}
View Code

yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及SUSE中的Shell前端软件包管理器。基於RPM包管理,能够从指定的服务器自动下载RPM包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软体包,无须繁琐地一次次下载、安装。yum提供了查找、安装、删除某一个、一组甚至全部软件包的命令,而且命令简洁而又好记。

yum的命令形式一般是如下:yum [options] [command] [package ...]
其中的[options]是可选的,选项包括-h(帮助),-y(当安装过程提示选择全部为"yes"),-q(不显示安装的过程)等等。[command]为所要进行的操作,[package ...]是操作的对象。

概括了部分常用的命令包括:

自动搜索最快镜像插件: yum install yum-fastestmirror
安装yum图形窗口插件: yum install yumex
查看可能批量安装的列表: yum grouplist

tar是用来建立,还原备份文件的工具程序,它可以加入,解开备份文件内的文件。

语法:

tar [-ABcdgGhiklmMoOpPrRsStuUvwWxzZ]
[-b <区块数目>]
[-C <目的目录>]
[-f <备份文件>]
[-F <Script文件>]
[-K <文件>]
[-L <媒体容量>]
[-N <日期时间>]
[-T <范本文件>]
[-V <卷册名称>]
[-X <范本文件>]
[-<设备编号><存储密度>]
[--after-date=<日期时间>]
[--atime-preserve]
[--backuup=<备份方式>]
[--checkpoint]
[--concatenate]
[--confirmation]
[--delete][--exclude=<范本样式>]
[--force-local]
[--group=<群组名称>]
[--help]
[--ignore-failed-read]
[--new-volume-script=<Script文件>]
[--newer-mtime]
[--no-recursion][--null]
[--numeric-owner]
[--owner=<用户名称>]
[--posix]
[--erve]
[--preserve-order]
[--preserve-permissions]
[--record-size=<区块数目>]
[--recursive-unlink]
[--remove-files]
[--rsh-command=<执行指令>]
[--same-owner]
[--suffix=<备份字尾字符串>]
[--totals]
[--use-compress-program=<执行指令>]
[--version]
[--volno-file=<编号文件>]
[文件或目录...]
View Code

原文地址:https://www.cnblogs.com/http-500/p/12072755.html