CentOS7源码安装Nginx
2024-09-01 02:20:26
系统平台:腾讯云服务器 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
最新文章
- Jenkins若干小问题
- php日期,时间相关知识整理
- WCF配置与服务寄宿
- 前端JSON使用总结
- 【HAOI2009】【P1307】毛毛虫
- WinFrom界面框架之WeifenLuo.WinFormsUI.Docking + OutLookBar
- bzoj3531
- hdu 2612 Find a way(BFS)
- block的一点知识
- MODULE_AUTHOR、MODULE_DESCRIPTION、MODULE_LICENSE宏
- node.js(三)url处理
- 第四章:Django 的模板系统(转)
- PHPCMSV9上线方法及文件权限设置
- 《CLR via C#(第4版)》【PDF】下载
- sql server 分区(上)
- Nginx与前端开发
- Visual C++ 6.0中if语句的常见问题
- Js 常用调试的方法
- SpringMVC环境搭建——HelloWorld
- C++ stringstream格式化输出输入探索
热门文章
- CS代码代写, 程序代写, java代写, python代写, c/c++代写,csdaixie,daixie,作业代写,代写
- 你一定能看懂的JDK动态代理
- 不一样的go语言-玩转语法之二
- 3D echarts 点位报表展示
- JavaScript 词法作用域不完全指北
- 正确写网站title、keywords、description
- 解析Unicode转义序列带来的问题
- .NetCore应用多个target framework
- Java集合类的概述
- android网络编程-socket基础