1.下载源码包,官网找最新稳定版本
```
wget http://nginx.org//download/nginx-1.16.0.tar.gz
```
也可以直接官网下载到PC本地 xshell 使用rz命令上传 或是ftp上传
2.解压.通常下载到/usr/local/src ,直接解压到该目录,用来专门放置安装压缩包和解压源码
3.配置参数.
```
./configure --help #查看可以设置哪些参数
```
其中 --prefix=install_path 这个参数是指定 make install的时候 软件安装的目录
4.编译
```
make [按照Makefile生成模块]
```
5.安装
```
make install
```
###以nginx为例
1.基础概念和依赖
nginx安装可以使用yum或源码安装,推荐使用源码,一是yum的版本比较旧,二是使用源码可以自定义功能,方便业务的上的使用,源码安装需要提前准备标准的编译器,GCC的全称是(GNU Compiler collection),其有GNU开发,并以GPL即LGPL许可,是自由的类UNIX即苹果电脑Mac OS X操作系统的标准编译器,因为GCC原本只能处理C语言,所以原名为GNU C语言编译器,后来得到快速发展,可以处理C++,Fortran,pascal,objective-C,java以及Ada等其他语言,此外还需要Automake工具,以完成自动创建Makefile的工作,Nginx的一些模块需要依赖第三方库,比如pcre(支持rewrite),zlib(支持gzip模块)和openssl(支持ssl模块)
官网http://nginx.org/en/download.html下载最新稳定版本到本地 本例子
登录Xshell连接服务器[阿里云ECS]
```
yum install lrzsz #用来使用rz命令
cd /usr/local/src #进入用户编译安装源码目录
rz # rz是代表上传 会弹出window的选择文件窗口,找到上面步骤下载的压缩包,确定后会下载到当前目录下
yum install gcc gcc-c++ automake pcre pcre-devel zlip zlib-devel openssl openssl-devel # 安装nginx的编译依赖
```
2.解压
```
tar -vxf nginx-1.16.0.tar.gz # 解压到当前目录
ll #查看解压后的当前目录下的所有文件 # 主要目的看解压后的文件名,一般为去掉压缩为后缀的文件名,此处为nginx-1.16.0
cd nginx-1.16.0
```
3.配置编译安装参数[如果想自己管理自己的软件安装,注意配置--prefix=你管理自己编译安装软件的目录路径]
```
./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/usr/local/nginx/logs/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre
```
4.make [编译]
```
我在这里出现两个问题 . 解决方案应该都在编译前就执行
>编译参数指定了用户和用户组 如果不存在会报错 所以要先创建nginx用户
> adduser nginx
> groupadd nginx
>编译参数指定了日志目录 可能该目录目录路径没有可写权限 比如 日志放在 /var/log/nginx/下 但是 /var 目录不可写 会导致安装报错
```
5.make install [安装]
此文章仅为学习记录,原文章步骤非常详细和好理解,见https://www.cnblogs.com/zhang-shijie/p/5294162.html
后续使用
```
/usr/local/nginx/sbin/nginx #启动nginx,通常没有输出任何信息,且下一步满足即成功
#遭遇了netstat -ntlp #查看网络连接进程,看到nginx进程即为成功,
# 如果 -bash: netstate: command not found 则 yum install net-tools
#在浏览器输入服务器IP或解析过的域名
#会显示/usr/local/nginx/html/index.html
```
启动过程可能会提示/var/run/nginx/nginx.pid 不存在或是不是一个文件之类的提示
建议调整配置文件/usr/local/nginx/conf/nginx.conf里的pid参数,指定/usr/local/nginx/logs/nginx.pid [记得先创建logs目录]
设置为开机自启
创建nginx启动命令脚本
```
vim /etc/init.d/nginx #内容如下
```
插入以下内容, 注意修改PATH和NAME字段, 匹配自己的安装路径 (这段是从网上copy的) 不过查看了相关参数,跟我的编译参数完全匹配
```
#! /bin/bash
# Startup script for the nginx Web Server
# chkconfig: - 85 15
# description: nginx is a World Wide Web server. It is used to serve
PATH=/usr/local/nginx
DESC="nginx daemon"
NAME=nginx
DAEMON=$PATH/sbin/$NAME
CONFIGFILE=$PATH/conf/$NAME.conf
PIDFILE=$PATH/logs/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
set -e
[ -x "$DAEMON" ] || exit 0
do_start() {
$DAEMON -c $CONFIGFILE || echo -n "nginx already running"
}
do_stop() {
$DAEMON -s stop || echo -n "nginx not running"
}
do_reload() {
$DAEMON -s reload || echo -n "nginx can't reload"
}
case "$1" in
start)
echo -n "Starting $DESC: $NAME"
do_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
do_stop
echo "."
;;
reload|graceful)
echo -n "Reloading $DESC configuration..."
do_reload
echo "."
;;
restart)
echo -n "Restarting $DESC: $NAME"
do_stop
do_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2
exit 3
;;
esac
exit 0
```
设置执行权限
```
chmod a+x /etc/init.d/nginx
```
注册成服务
```
chkconfig --add nginx
```
设置开机启动
```
chkconfig nginx on
```
重启, 查看验证nginx服务是否自动启动
```
#重启
reboot #或
shutdown -h 0 -r
#查看进程
ps aux | grep nginx #或
netstat -nplt | grep nginx
```
对nginx服务执行停止/启动/重新读取配置文件操作
```
#启动nginx服务
systemctl start nginx.service
#停止nginx服务
systemctl stop nginx.service
#重启nginx服务
systemctl restart nginx.service
#重新读取nginx配置(这个最常用, 不用停止nginx服务就能使修改的配置生效)
systemctl reload nginx.service
```
成功
# 配置将请求转发给php-fpm处理 php-fpm的默认端口号是9000
主配置
```
user www;
worker_processes 1;
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 65;
#gzip on;
#开启所有的虚拟主机目录可访问,想要仅指定的主机的目录可访问 去对应的server下配置
#autoindex on;
#autoindex_exact_size off;
##autoindex_exact_size off;
#虚拟主机配置 自动加载
include /usr/local/nginx/conf/nginx.conf.vhost/*.conf;
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;
# }
#}
}
```
虚拟主机配置
```
# another virtual host using mix of IP-, name-, and port-based configuration
#
server {
charset utf-8;
listen 80;
server_name blog.54skyer.cn;
set $root /home/www/blog.54skyer.cn/public;
root $root;
#root /home/www/blog.54skyer.cn/public;
index index.php index.html;
location /zhanghaotian/ {
autoindex on;
}
location / {
# 如果根目录下匹配不是脚本 默认在根目录后拼一个index.php 这是为了在url中省略index.php
if (!-e $request_filename){
rewrite ^(.*) /index.php/$1 last;
break;
}
}
#pathinfo配置 使支持tp5的标准url
location ~ .+\.php($|/) {
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^((?U).+.php)(/?.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $root$fastcgi_script_name;
include fastcgi_params;
}
# 匹配到php扩展名的url
#location ~\.php$ {
# include /usr/local/nginx/conf/fastcgi.conf;
# fastcgi_intercept_errors on;
# #转发给php-fpm,其端口是9000;
# fastcgi_pass 127.0.0.1:9000;
#}
}
# 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;
# }
#}
```
- 常见功能
- 第三方授权登录
- 邮件发送
- 简易聊天室
- 获取各国汇率
- PHP获取服务器硬件指标
- 数据上报之
- web开发
- 开发规范
- 前端
- 踩坑
- 将footer固定在底部
- bootstrap
- Metronic
- 用到的jquery插件
- bootstrap-hover-dropdown
- jquery.slimscroll
- jquery.blockui
- bootstrap-switch
- js.cookie
- moment
- bootstrap-daterangepicker
- morris
- raphael
- jquery.waypoints
- jquery.counterup
- select2
- 取值和设置默认值
- vue
- axios
- 浏览器
- 谷歌浏览器
- 谷歌插件
- layui
- layui-表格
- layui-表单
- layui-弹窗
- layui-分页
- 后端
- 操作系统
- linux
- 用户管理
- 文件管理
- 目录管理
- 压缩和解压缩
- 进程查看
- 端口查看
- 开机自启动服务
- 定时任务
- shell脚本
- 杀掉运行超过指定时长指定服务的进程
- 获取服务器使用状态
- bash-shell连接socket
- 自定义快捷命令
- centos-踩坑
- 防火墙
- 软件
- yum
- vim
- screen
- window
- 语言
- PHP
- 配置优化
- 框架
- thinkphp5.1+
- think命令行
- laravel6.+
- 维护模式
- 根据环境读取不同配置
- laravel6.+采坑
- laravel坑位
- 数据库事务
- 任务调度
- 文件权限问题
- 增强框架
- larvel:elastic-search
- 图形验证码
- laravel获取ip
- 函数
- strtotime
- 正则匹配
- 类
- 接口类与抽象类
- 类相关的关键字 - abstract
- 类相关的关键字 - interface
- PHP有关类的调用方式"->"与"::"的区别
- 扩展
- 问题归纳
- json_encode和json_decode
- 字符串的运算
- curl
- 优化php效率
- 数组相加合并与array_merge
- 时区转换
- 不常用特性
- php反射
- 包管理器-composer
- GuzzleHttp
- Python
- Go
- 数据库
- Redis
- 安装
- 本地化-数据备份
- php-redis操作
- Mysql
- mysql-命令集合
- 设置终端可访问
- 数据库设计
- 用户基础信息表
- 踩坑集合
- mysql-2002
- mysql-2054
- 优化策略
- mysql-密码验证插件
- 一些牛逼的sql查询
- topN
- 无限级分类
- Memcache
- MongoDb
- 安装mongo-server
- 安装php-mongodb扩展
- 在laravel中使用mongoDB
- 客户端软件
- Hbase
- Elasticsearch
- elastic-search
- restfulApi操作es
- web服务器
- 1.nginx
- 配置语法规则
- 配置详解
- rewrite规则
- request_filename
- 2.apache
- 功能设计
- 加密解密
- Base64
- 对亚马逊SKU加密
- 兼职项目中的加解密
- 腾讯外包时的加密
- 接口设计
- 接口限流设计
- 分库分表
- 遍历展示文件目录结构
- 时区换算
- 文件切割
- 解析xml字符串
- 项目
- 博客后台管理
- 亚马逊广告API
- 官方指引文档
- 开发人员中心
- 应用商店
- 第三方库
- 申请API邮件记录
- 亚马逊MWS
- 付款报告
- 乱码
- 亚马逊管理库存报告
- 报告
- 商品
- 入库
- 履行
- 出库
- 财务
- 订单
- 异步任务处理
- 集群如何同步代码
- 基本开发流程
- 文档管理
- showdoc
- 运行环境
- 开发环境
- vagrant
- windows上配置安装
- vagrant安装插件缓慢
- 更换ssh默认端口映射
- 设置x-shell密码登录
- 使用市场的box-homestead
- homestead-7: Box 'lc/homestead'
- 常见问题
- 虚拟环境reboot
- 突然无法使用
- phpStudy
- wamp
- 压测性能
- VPN
- vultr
- 凌空图床
- 宝塔
- 自动化部署
- 版本管理软件钩子
- 线上环境-LNMP
- centos7
- nginx
- mysql
- mysql开机自启
- mysql-更换默认端口
- datetime字段类型默认值
- php
- php扩展安装
- redis
- swoole
- gd
- BCMath
- igbinary
- zstd
- 包管理器:composer
- 优化性能
- nodejs
- 更新gcc版本
- 版本控制
- git
- 常用命令
- gitlab
- 版本管理规范
- 使用阿里云创建远程仓库
- git自动化部署
- svn
- 忽略指定文件
- 拉取代码
- 自动化运维
- jekins
- 容器
- 集群
- 架构设计
- 设计原则
- 阅读参考
- 代码规划
- 架构实战
- 服务治理
- 权限控制设计
- 具体设计
- 计划
- 疑问知识点
- 读书笔记
- 高性能Mysql
- TCP-IP详解-卷一:协议
- 思考
- php如何实现并发执行
- 对接调用设计
- 如何在浏览器上实现插件
- 如何设计一个app结合业务告警
- mysql的where查询没有用到索引
- 为啥in查询比循环嵌套sql的查询还要慢
- 使用git来创建属于自己的composer包
- 翻页获取数据的时候又新增了数据
- 安全思路
- 月报
- PHP ?? 和 ?: 的区别
- PHP异步执行
- redis集群的目标是什么
- 大文件数据处理
- 性能瓶颈分析
- 命令行里输出带颜色的字体
- 面试问题合集
- 基础
- 安全
- 算法
- 冒泡排序
- 快速排序
- 二分法查询数组指定成员
- 字符查找匹配
- 令牌桶
- 漏桶
- 计数器
- 代理
- 协议
- http
- 状态码
- tcp
- udp
- Oauth2.0
- 设计模式
- 单例模式
- 适配器模式
- 工厂模式
- 观察者模式
- 流程化
- 地址栏输入网址到返回网页的流程
- 题目收集
- 工具
- rabbitMq
- rabbitMQ用户管理
- 生产者
- 消费者
- 支持TP5.*的think-queue
- 消息丢失
- 消费者报错
- rabbitMQ配置优化
- 磁盘满载导致服务挂掉
- PHP类库
- rabbitMQ踩坑
- navicat
- vscode
- phpstorm
- 激活码
- markdown
- PHP自定义类库
- 工具类
- 领导力
- 任务分配
- 代码组织
- 不要重复
- 避免污染
- 接口定义规范
- 小业务需求
- 获取充值面额组成
- 监控服务器CPU和内存
- shell脚本版本