系统平台:腾讯云服务器 CentOS 7.3 64位

一、安装编译工具及库文件

[root@VM_0_5_centos ~]# yum install -y make zlib zlib-devel gcc-c++ libtool openssl openssl-devel

二、安装pcre

PCRE 作用是让 Nginx 支持 Rewrite 功能。

1 、下载PCRE包
[root@VM_0_5_centos ~]# cd /usr/local/src/
[root@VM_0_5_centos src]# wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
2、解压安装包

[root@VM_0_5_centos src]# tar zxvf pcre-8.35.tar.gz

3、进入解压后安装包目录

[root@VM_0_5_centos src]# cd pcre-8.35

4、编译安装
[root@VM_0_5_centos pcre-8.35]# ./configure
[root@VM_0_5_centos pcre-8.35]# make
[root@VM_0_5_centos pcre-8.35]# make install
5、查看pcre版本
[root@VM_0_5_centos pcre-8.35]# pcre-config --version
8.35

三、安装Nginx

1、下载Nginx
[root@VM_0_5_centos ~]# cd /usr/local/src/
[root@VM_0_5_centos src]# wget http://nginx.org/download/nginx-1.16.0.tar.gz
2、解压安装包

[root@VM_0_5_centos src]# tar zxvf nginx-1.16.0.tar.gz

3、进入解压后的目录

[root@VM_0_5_centos src]# cd nginx-1.16.0

4、编译安装
[root@VM_0_5_centos nginx-1.16.0]# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.35
[root@VM_0_5_centos nginx-1.16.0]# make
[root@VM_0_5_centos nginx-1.16.0]# make install

--prefix指定安装路径

5 、查看nginx版本
[root@VM_0_5_centos nginx-1.16.0]# /usr/local/nginx/sbin/nginx -v
nginx version: nginx/1.16.0

四、Nginx 配置

创建Nginx运行使用的用户www

[root@VM_0_5_centos ~]# groupadd www
[root@VM_0_5_centos ~]# useradd -g www www

修改配置文件

[root@VM_0_5_centos ~]# vim /usr/local/nginx/conf/nginx.conf

user  www www; #指定用户名和组名
worker_processes 1; #设置值和cpu核心数一致 error_log logs/error.log;
error_log logs/error.log notice;
error_log logs/error.log info; pid logs/nginx.pid; events {
worker_connections 1024;
} http {
include 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 logs/access.log main; sendfile on;
tcp_nopush on; #keepalive_timeout 0;
keepalive_timeout 60; #gzip on; 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$ {
# 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;
#}
} # 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; # location / {
# root html;
# index index.html index.htm;
# }
#} }

后续根据需要配置;

检查配置文件nginx.conf的正确性命令:

[root@VM_0_5_centos conf]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

五、启动Nginx

[root@VM_0_5_centos conf]# /usr/local/nginx/sbin/nginx

六、Nginx其他查用命令

[root@VM_0_5_centos conf]# /usr/local/nginx/sbin/nginx -s reload   #重新载入配置文件
[root@VM_0_5_centos conf]# /usr/local/nginx/sbin/nginx -s reopen #重启Nginx
[root@VM_0_5_centos conf]# /usr/local/nginx/sbin/nginx -s stop #停止nginx

CentOS7源码安装Nginx的更多相关文章

  1. centos7 源码安装nginx

    1. 安装编译所需要的工具包 yum -y install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel 2. 安装ngi ...

  2. 源码安装nginx env

    源码安装nginx 1. For ubuntu:18.04 apt -y install build-essential libtool libpcre3 libpcre3-dev zlib1g-de ...

  3. 源码安装nginx以及平滑升级

                                                           源码安装nginx以及平滑升级                               ...

  4. Linux之源码安装nginx,并按照作业一描述的那样去测试使用

    作业五:源码安装nginx,并按照作业一描述的那样去测试使用 [root@localhost nginx]# yum install gcc-* glibc-* openssl openssl-dev ...

  5. 源码安装Nginx以及用systemctl管理

    一.源码安装Nginx: 先安装gcc编译器(安装过的可以忽略) [root@localhost ~]# yum -y install gcc gcc-c++ wget 进入src目录 [root@l ...

  6. centos7源码安装Python3的前提条件

    centos7源码安装Python3的前提条件: # yum -y install openssl-devel bzip2-devel expat-devel gdbm-devel readline- ...

  7. linux源码安装nginx

    任务目标:源码安装nginx,作为web服务修改配置文件,让配置生效,验证配置 首先要去官网nginx.org下载一个tar包: tar xvf 解包 进入到解包出来的目录,对configure进行配 ...

  8. 工作笔记-- 源码安装nginx

    源码安装nginx 1.安装nginx的依赖包 [root@localhost ~]# yum -y install gcc gcc-c++ openssl openssl-devel pcre pc ...

  9. 源码安装nginx 方法二

    yum 仓库不能用大写字母 [root@oldboy conf.d]# gzip * 压缩当前目录下的所有文件 gzip ./* gzip . gzip./ # 关闭防火墙和selinux [root ...

随机推荐

  1. 【搜索引擎】Solr全文检索近实时查询优化

    设置多个搜索建议查找算法 <searchComponent name="suggest" class="solr.SuggestComponent"> ...

  2. 转:Mongoose使用操作

    一般我们不直接用MongoDB的函数来操作MongoDB数据库 Mongose就是一套操作MongoDB数据库的接口.   连接数据库 // mongoose 链接var mongoose = req ...

  3. Unity Shader 玻璃效果

    一个玻璃效果主要分为两个部分,一部分是折射效果的计算,另一部分则是反射.下面分类进行讨论: 折射: 1.利用Grass Pass对当前屏幕的渲染图像进行采样 2.得到法线贴图对折射的影响 3.对采集的 ...

  4. 解决kali linux 2016.2实体机安装后root用户没有声音

    Kali Linux系统默认状态下,root用户是无法使用声卡的,也就没有声音.启用的方法如下:(1)在终端执行命令:systemctl --user enable pulseaudio (2)在/e ...

  5. Scala 学习之路(十三)—— 隐式转换和隐式参数

    一.隐式转换 1.1 使用隐式转换 隐式转换指的是以implicit关键字声明带有单个参数的转换函数,它将值从一种类型转换为另一种类型,以便使用之前类型所没有的功能.示例如下: // 普通人 clas ...

  6. laravel-admin(自定义表单视图)

    前言: 在上一遍文章(https://www.cnblogs.com/shiwenhu/p/10271013.html)中写到可以使用自定义form组建来创建表单,几乎能满足我们大部分要求,而且不用我 ...

  7. JavaScript 事件(捕获和冒泡 兼容性写法)

    事件    浏览器客户端上客户触发的行为都称为事件 所有的事件都是天生自带的 不需要人为绑定 只需要我们去触发通过obj.事件名=function(){} 我们给元素的事件绑定了一个方法 事件名:on ...

  8. SQL 对float类型列进行排序引发的异常

    车祸现场 要求:根据学分和完成时间获取前200名学员,当学分相同时,完成时间较早的排在前面 可以明显看到,完成时间为4.1号的记录排在了3.27号前面. 事故原因 float 表示近似数值,存在精度损 ...

  9. 2018.10.1 2018NOIP冲刺之立体图

    2008NOIP普及组立体图 请自行百度(事实上放不下了) 图不是很清楚 下面有 [输入] 输入文件 drawing.in 第一行有用空格隔开的 2 个整数 m 和 n,表示有 m*n  个格子 (1 ...

  10. 1、Java简介

    Java SE: 最基础的部分,java的标准版本: Java EE: 企业版,(JSP.EJB.服务) Java ME:移动设备.游戏.通信 JVM: java virtual machine    ...