CentOS7源码安装Nginx
系统平台:腾讯云服务器 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的更多相关文章
- centos7 源码安装nginx
1. 安装编译所需要的工具包 yum -y install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel 2. 安装ngi ...
- 源码安装nginx env
源码安装nginx 1. For ubuntu:18.04 apt -y install build-essential libtool libpcre3 libpcre3-dev zlib1g-de ...
- 源码安装nginx以及平滑升级
源码安装nginx以及平滑升级 ...
- Linux之源码安装nginx,并按照作业一描述的那样去测试使用
作业五:源码安装nginx,并按照作业一描述的那样去测试使用 [root@localhost nginx]# yum install gcc-* glibc-* openssl openssl-dev ...
- 源码安装Nginx以及用systemctl管理
一.源码安装Nginx: 先安装gcc编译器(安装过的可以忽略) [root@localhost ~]# yum -y install gcc gcc-c++ wget 进入src目录 [root@l ...
- centos7源码安装Python3的前提条件
centos7源码安装Python3的前提条件: # yum -y install openssl-devel bzip2-devel expat-devel gdbm-devel readline- ...
- linux源码安装nginx
任务目标:源码安装nginx,作为web服务修改配置文件,让配置生效,验证配置 首先要去官网nginx.org下载一个tar包: tar xvf 解包 进入到解包出来的目录,对configure进行配 ...
- 工作笔记-- 源码安装nginx
源码安装nginx 1.安装nginx的依赖包 [root@localhost ~]# yum -y install gcc gcc-c++ openssl openssl-devel pcre pc ...
- 源码安装nginx 方法二
yum 仓库不能用大写字母 [root@oldboy conf.d]# gzip * 压缩当前目录下的所有文件 gzip ./* gzip . gzip./ # 关闭防火墙和selinux [root ...
随机推荐
- Python基础,day1
一. Python介绍 目前Python主要应用领域: 云计算: 云计算最火的语言, 典型应用OpenStack WEB开发: 众多优秀的WEB框架,众多大型网站均为Python开发,Youtube, ...
- Spring Boot2(三):使用Spring Boot2集成Redis缓存
前言 前面一节总结了SpringBoot实现Mybatis的缓存机制,但是实际项目中很少用到Mybatis的二级缓存机制,反而用到比较多的是第三方缓存Redis. Redis是一个使用ANSI C编写 ...
- [代码修订版] Python 踩坑之旅进程篇其五打不开的文件
目录 1.1 踩坑案例 1.2 填坑和分析 1.2.1 从程序优化入手 1.2.2 从资源软硬限入手 1.4.1 技术关键字 下期坑位预告 代码示例支持 平台: Centos 6.3 Python: ...
- 你竟然没用 Maven 构建项目?
一年前,当我和小伙伴小龙一起做一个外包项目的时候,受到了严重的鄙视.我那时候还不知道 Maven,所以搭建项目用的还是最原始的方式,小龙不得已在导入项目的时候花了很长时间去下载项目依赖的开源类库. 出 ...
- 戏说 .NET GDI+系列学习教程(一、Graphics类--纸)
Graphics类(纸) Graphics类封装一个GDI+绘图图面,提供将对象绘制到显示设备的方法,Graphics与特定的设备上下文关联. 画图方法都被包括在Graphics类中,在画任何对象时, ...
- 【linux杂记】Ubuntu查看端口使用情况
转载地址: https://www.linuxidc.com/Linux/2016-01/127345.htm Ubuntu查看端口使用情况,使用netstat命令: 查看已经连接的服务端口(ESTA ...
- Django生成PDF显示在网页上以及解决中文显示乱码的问题
项目地址:https://github.com/PythonerKK/django-generate-pdf/tree/master 这个demo实现了通过用户输入自己的个人信息生成一份简历pdf,来 ...
- 记录微信浏览器里word链接点击没反应的bug
有用户反应点击下载附件时没有反应,让用户把该下载链接复制到微信对话框中,发现点击该链接仍然无反应,但是在内置的手机浏览器中打开是正常的而且可以下载. 链接地址,有需要的可以拿去进行测试: http:/ ...
- leadcode的Hot100系列--617. 合并二叉树
合并,就是两个树的结构交集部分,数据相加,否则,取非空部分. 所以,这里相当于是对两棵树同时遍历: 如果两棵树节点都不为空,则数据相加, 否则,直接指针把不为空的节点复制过来. 注:这里没有申请内存, ...
- 多线程与高并发(四)volatile关键字
上一篇学习了synchronized的关键字,synchronized是阻塞式同步,在线程竞争激烈的情况下会升级为重量级锁,而volatile是一个轻量级的同步机制. 前面学习了Java的内存模型,知 ...