环境,glibc安装mysql,yum源配好epel

1.安装依赖

# yum -y install pcre-devel zlib-devel openssl-devel

2.下载nginx

官网:http://www.nginx.org

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

# cd /software
# wget http://nginx.org/download/nginx-1.16.1.tar.gz
# tar xf nginx-1.16.1.tar.gz
# cd nginx-1.16.1
# useradd -r -s /sbin/nologin www
# ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module
# make && make install启动Nginx软件
# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf停止Nginx
# /usr/local/nginx/sbin/nginx -s stop

3.Nginx/Apache的区别

Apache与PHP的之间的关系:PHP是以模块的形势加载在Apache的内核中。在解析动态PHP代码时,其效率较高。LoadModule

Nginx与PHP之间的关系:Nginx与PHP相对而言都是独立的,只不过在应用过程中,解析动态脚本时,Nginx会自动源代码发送给PHP-FPM程序。Nginx在处理静态页面时,效率较高。

4.安装PHP-FPM

安装依赖库

#  yum -y install libxml2-devel libjpeg-devel libpng-devel freetype-devel curl-devel openssl-devel
# cd /software
# wget https://www.php.net/distributions/php-7.2.23.tar.bz2
# tar xf php-7.2.23.tar.bz2
# cd php-7.2.23
# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-ftp --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --with-libzip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-ztsThank you for using PHP.
成功
# 请确保机器内存不小于512MB
# make && make install...漫长的等待...Build complete.
成功

5.配置PHP-FPM

# cp /software/php-7.2.23/php.ini-development /usr/local/php/etc/php.ini
# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
# cp /software/php-7.2.23/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
# chmod +x /etc/init.d/php-fpm
# service php-fpm start
# ss -nltp9000端口被php-fpm占用
成功加入环境变量
# echo 'export PATH=$PATH:/usr/local/php/bin' >> /etc/profile
# source /etc/profile

6.关联nginx与php

上项目之前先授权。
# chown www.www -R /usr/local/nginx# cd /usr/local/nginx/html
# vim demo.php<?php phpinfo(); ?># vim /usr/local/nginx/conf/nginx.conf在
location / {root   html;index  index.html index.htm;
}
后面添加location ~ \.php$ {fastcgi_pass   127.0.0.1:9000;fastcgi_index  index.php;fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;include        fastcgi_params;
}
保存退出重启nginx
# /usr/local/nginx/sbin/nginx -s stop
# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf访问
http://10.1.1.10/demo.php
可以解析php代码啦~

7.升级nginx

接上文,升级nginx到1.17.5

# 查看当前nginx版本
# /usr/local/nginx/sbin/nginx -v
显示
nginx version: nginx/1.16.1# 后续程序一样,下载一个更高版本,同样的配置,安装同样的目录# cd /software
# wget http://nginx.org/download/nginx-1.17.5.tar.gz
# tar xf nginx-1.17.5.tar.gz
# cd nginx-1.17.5
# ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module
# make && make install# 原处安装两个nginx的反应就是# ll /usr/local/nginx/sbin/
-rwxr-xr-x 1 root root 5991776 Nov  7 21:24 nginx
-rwxr-xr-x 1 root root 5983944 Nov  6 14:43 nginx.old
# nginx.old是原来nginx的,nginx是新版本的。
# 验证
# /usr/local/nginx/sbin/nginx -v
nginx version: nginx/1.17.5
# /usr/local/nginx/sbin/nginx.old -v
nginx version: nginx/1.16.1

安装完毕之后,要优雅的切换版本。

# 原理:开启两个nginx进程,每一个nginx进程都有一个master和若干个worker。
# 先关闭worker进程,再优雅得退出master进程
# 优雅?如果直接关闭服务再开启也行,但是如果线上环境就需要不停服,优雅得升级# 查看nginx的PID
# ps -ef | grep nginx
root      1216     1  0 21:32 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
www       1217  1216  0 21:32 ?        00:00:00 nginx: worker process
root      1219  1196  0 21:32 pts/0    00:00:00 grep --color=auto nginx如上master的PID是1216# 拉起两个nginx进程
# kill -usr2 1216
# ps -ef | grep nginx
root      1216     1  0 21:32 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
www       1217  1216  0 21:32 ?        00:00:00 nginx: worker process
root      1220  1216  2 21:33 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
www       1221  1220  0 21:33 ?        00:00:00 nginx: worker process
root      1223  1196  0 21:33 pts/0    00:00:00 grep --color=auto nginx
# 有两个nginx了# 关闭旧nginx的worker
# kill -winch 1216(要输入master的PID来关闭worker)
# 优雅的关闭旧master
# kill -quit 1216完毕

8.配置文件与虚拟主机

nginx.conf文件初探

可以精简nginx.conf文件
cd /usr/local/nginx/conf
grep -Ev '#|^$' nginx.conf > nginx.conf1
mv nginx.conf1 nginx.conf关注重点http{}区域
首先,配置文件中仅可以存在一个http{}区域
其次,一个http{}中可以存在多个server{}区域http {include       mime.types;     # include引入文件 mime.types里是nginx可处理的所有文件格式default_type  application/octet-stream;    # 默认以8位文件流模式传输文件sendfile        on;    # 略keepalive_timeout  65;    # 保持连接时间server {    # server区域,虚拟主机设置点listen       80;    # 监听端口server_name  localhost;    # 主机名称location / {    # 默认访问root   html;    # 项目程序路径index  index.html index.htm;    # 默认主页文件}location ~ \.php$ {    # 需要解析php文件就写上这段fastcgi_pass   127.0.0.1:9000;fastcgi_index  index.php;fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;include        fastcgi_params;}}      error_page   500 502 503 504  /50x.html;     # 默认报错页面。location = /50x.html {root   html;}
}# 修改配置要重启nginx
# /usr/local/nginx/sbin/nginx -s reload服务器端结束虚拟主机访问端需要修改host
windows下hosts在
C:\Windows\System32\drivers\etc\hosts
linux下hosts在
/etc/hosts修改方法一样
增加一行# IP    上面设定的自定义域名
例如
10.1.1.10    www.h5.com修改完毕保存,访问验证即可。

如果要设置虚拟主机,则增加一个server区域

http {...略...server {原来的}server {listen       80;server_name  虚拟主机域名;location / {root   虚拟主机项目路径;index  index.html index.htm;}location ~ \.php$ {fastcgi_pass   127.0.0.1:9000;fastcgi_index  index.php;fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;include        fastcgi_params;}}      error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}}其本质就是复制了一遍,改俩地方

LNMP搭建,nginx安装,php-fpm,版本升级,配置虚拟主机相关推荐

  1. LNMP(linux+nginx+mysql+php)服务器环境配置

    LNMP(linux+nginx+mysql+php)服务器环境配置 一.简介 Nginx是俄罗斯人编写的十分轻量级的HTTP服务器,Nginx,它的发音为 "engine X", ...

  2. nginx安装及负载均衡配置

    Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器. Nginx 是由 Igor Sysoev ...

  3. Nginx安装与使用(配置详解)

    前言 Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行.由俄罗斯的程序设计师Igor Sysoev所开发,供俄国大 ...

  4. Linux 配置LNMP服务器 并配置虚拟主机

    2019独角兽企业重金招聘Python工程师标准>>> 一.停止甚至删除系统上现有的web服务器软件 为了防止出现意外情况,建议先卸载现有的所有web服务器资源,如apache.my ...

  5. javaweb学习总结十七(web应用组织结构、web.xml作用以及配置虚拟主机搭建网站)

    一:web应用组织结构 1:web应用组成结构 2:安装web组成机构手动创建一个web应用程序目录 a:在webapps下创建目录web b:在web目录下创建html.jsp.css.js.WEB ...

  6. nginx 配置虚拟主机

    文章转载自:http://www.ttlsa.com/html/1571.html 上篇说道我们的nginx是安装在/usr/local/nginx/ cd conf 我们现在把所有的虚拟主机放在一个 ...

  7. 正向代理和反向代理的区别Nginx配置虚拟主机流程(后续更新)

    目录 目标 安装Nginx 配置虚拟主机 准备 方法一 方法二(推荐) 验证虚拟主机 正向代理和反向代理的区别 区别&案例 正向代理和反向代理流程 目标 熟练在Linux安装单机Nginx: ...

  8. Nginx基于IP,端口,域名配置虚拟主机

    Nginx(发音同 engine x)是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行.其特点是占有内存少,并发能力强,事实 ...

  9. Nginx(二)配置虚拟主机

    1.配置虚拟主机 虚拟主机,也叫"⽹站空间",就是把⼀台运⾏在互联⽹上的物理服务器划分成多个"虚拟"服务器.虚拟主 机技术极⼤的促进了⽹络技术的应⽤和普及.同时 ...

  10. Nginx配置虚拟主机三种方式

    Nginx 配置虚拟主机,总共有三种方式,基于多IP,基于多端口,基于多域名,其中基于多域名是企业中最常用的一种方式,基于多端口的方式,主要用于本机配置项目. nginx参数详解 基于多IP的方式 [ ...

最新文章

  1. ZooKeeper简单使用
  2. Java项目:医院管理系统(java+Springboot+Maven+Mybatis+Vue+Mysql)
  3. WMS(二):Window的删除过程
  4. 水泵调速c语言实验程序,C语言实验最原始.doc
  5. python中的连续比较是什么_Python算法的分治算法,python,之,连续,子,列表,最大,和...
  6. 谷歌放弃go_用 Go 实现 Flutter
  7. HttpClient下载图片
  8. TP5.0Composer安装phpQuery
  9. 【ENVI】shp文件裁剪需要注意的问题
  10. 戴尔机架式服务器哪个型号好,戴尔_PowerEdge R540_机架式服务器参数_服务器推荐购买 | Dell 中国大陆...
  11. 春节假期最值得阅读的10本书
  12. python分位数回归模型_分位数回归及其Python源码
  13. CentOS7 建立静态 IP(eth0)
  14. 《影响中国大数据产业进程100人》 刘冬冬: 数据如何来支持新的商业战争
  15. 揪心!河南极端暴雨突袭,多地受灾严重!加油,河南
  16. 国外大数据初创公司巨额融资 国内公司初长成
  17. C++课程学习代码汇总基础
  18. 交换机的主要技术指标
  19. 浅谈什么是web应用防火墙(WAF)
  20. C语言文件操作+通讯录实现文件操作

热门文章

  1. python--英文文章单词数量统计
  2. ESP8266-Arduino编程实例-PCF8574IO扩展模块驱动
  3. 电脑怎么滚动截图的方法
  4. 伪元素(pseudo-elements)
  5. Java(基础)单例(Singleton)
  6. 计算机应用技术职业评测,2019年广安职业技术学院单招考试计算机应用技术、软件技术专业(中职类)职业技能测试大纲...
  7. 来闯关吗?​一个有趣的 Python 解谜网站
  8. nest.js学习笔记(一)
  9. PythonOpenCV识别视频人脸
  10. 【推荐系统案例】基于协同过滤的电影推荐