lnmp安装与配置

machongblogs machongblogs     2023-01-15     784

关键词:

LNMP安装与配置

1.安装前准备(确认apache和mysql端口无  有的话停止stop运行

1)关闭rpm默认安装的apache和mysql

[[email protected] ~]# chkconfig --list | grep httpd

[[email protected] ~]# chkconfig --list | grep mysqld

[[email protected] ~]#

2)selinux

[[email protected] selinux]# vi /etc/selinux/config

# This file controls the state of SELinux on the system.

# SELINUX= can take one of these three values:

#     enforcing - SELinux security policy is enforced.

#     permissive - SELinux prints warnings instead of enforcing.

#     disabled - No SELinux policy is loaded.

SELINUX=disabled

# SELINUXTYPE= can take one of these two values:

#     targeted - Targeted processes are protected,

#     mls - Multi Level Security protection.

SELINUXTYPE=targeted

重启服务reboot

 

3)禁用自启动

[[email protected] selinux]# vi /etc/rc.local

#!/bin/sh

#

# This script will be executed *after* all the other init scripts.

# You can put your own initialization stuff in here if you don‘t

# want to do the full Sys V style init stuff.

 

touch /var/lock/subsys/local  下面的所有开机自启动项全部删除

[[email protected] selinux]# source /etc/rc.local

 

4)保证yum源正常

A)mount 查看光盘是否挂载

B)没有挂载的话 挂载

[[email protected] selinux]# mount /dev/sr0 /mnt/cdrom

mount: block device /dev/sr0 is write-protected, mounting read-only

C)查看yum源是否可用

[[email protected] selinux]# yum list

5)准备lnmp其他的源代码包

http://lnmp.org/install.html下载 

技术分享图片 

 

2.一键安装过程

1)一键安装过程

官网下载源码包-->解压(tar zxvf lnmp1.0-full.tar.gz)-->cd到目录下-->执行一键安装./centos.sh脚本

您可以选择使用下载版(推荐国外或者美国VPS使用)或者完整版(推荐国内VPS使用),两者没什么区别。

执行安装程序前需要您确认您的Linux发行版,可以执行:cat /etc/issue 查看是CentOS、Debian还是Ubuntu,也可以通过VPS服务商提供的控制面板上查看。确定好之后,选择下面对应系统的安装命令: 

CentOS系统下执行:wget -c http://soft.vpser.net/lnmp/lnmp1.0-full.tar.gz && tar zxvf lnmp1.0-full.tar.gz && cd lnmp1.0-full && ./centos.sh

按上述命令执行后,会出现如下提示:
(注:如果是Debian系统,会提示Where are your servers located? asia,america,europe,oceania or africa,这里是选择服务器/VPS在哪个大洲,一般都是美国VPS,直接回车就行,如果是中国的,输入asia,回车。如果输入有错误,可以按住Ctrl再按Backspace键删除,以下均可采用此方法删除。)
技术分享图片
这一步需要设置MySQL的root密码,输入后回车进入下一步,如下图所示:
技术分享图片
这里需要确认是否启用MySQL InnoDB,如果不确定是否启用可以输入 y ,这个可以单独在MySQL文件里关闭,输入 y 表示启用,输入 n 表示不启用。输入 y 或 n 后回车进入下一步,显示如下信息:
技术分享图片
这一步是选择php版本,可以选择 PHP 5.3.17 或 PHP 5.2.17,安装PHP 5.3.17的话输入 y ,安装PHP 5.2.17 输入 n,输入 y 或 n 后回车,进入下一步MySQL版本的选择,如下图:
技术分享图片
可以选择MySQL 版本 5.5.27 或 5.1.60,安装MySQL 5.5.27的话输入 y ,安装MySQL 5.1.60 输入n,输入 y 或 n 后回车,完成选择。

提示"Press any key to start...",按任意键确认开始安装。
LNMP脚本就会自动安装编译Nginx、MySQL、PHP、phpMyAdmin、Zend Optimizer这几个软件。

安装时间可能会几十分钟到几个小时不等,主要是机器的配置网速等原因会造成影响。

2)、安装完成
如果显示如下界面:80端口
技术分享图片
说明已经安装成功。
接下来按添加虚拟主机教程,添加虚拟主机,通过sftpftp服务器上传网站,将域名解析到VPS或服务器的IP上,解析生效即可使用。

3)、安装失败
技术分享图片
如果出现类似上图的提示,则表明安装失败,说明没有安装成功!!需要用winscp或其他类似工具,将/root目录下面的lnmp-install.log下载下来,到LNMP支持论坛发帖注明你的发行版名称版本号(可通过 cat /etc/issue获得)、32位还是64位,并将lnmp-install.log压缩以附件形式上传到论坛,我们会通过日志查找错误,并给予相应的解决方法。

 

4)、eAccelerator,xcache,memcached,imageMagick,ionCube的安装

本文主要介绍eAcceleratorxcachememcachedimageMagickionCube这几个PHP加速和php扩展的安装及使用,这些不一定对每个人都有用,自己按需要安装,下面会对各个程序的作用、安装方法及相关注意事项。

a)、eAccelerator

eAccelerator是一个自由开放源码php加速器,优化和动态内容缓存,提高了php脚本的缓存性能,使得PHP脚本在编译的状态下,对服务器的开销几乎完全消除。 它还有对脚本起优化作用,以加快其执行效率。

安装
进入lnmp解压后的目录,执行:./eaccelerator.sh 运行后有如下提示:
技术分享图片
eaccelerator 0.9.5.3 支持PHP 5.2,如需此版本,输入 old 回车。
eaccelerator 0.9.6.1 支持PHP 5.2、5.3,如需此版本,输入 new 回车。
eaccelerator 1.0-dev 支持PHP 5.2、5.3、5.4,如需此版本输入 dev 回车。

提示“Press any key to start...or Press Ctrl+c to cancel” 后回车确认,脚本就会自动安装eaccelerator。

b)、xcache

XCache 是一个国人开发的又快又稳定的 PHP opcode 缓存器. 经过良好的测试并在大流量/高负载的生产机器上稳定运行. 经过(在 linux 上)测试并支持所有现行 PHP 分支的最新发布版本。

安装
进入lnmp解压后的目录,执行:./xcache.sh 运行后有如下提示:
技术分享图片
一个有两个版本可以选择,分别是XCache 2.0.0 和XCache 3.0.1 ,建议安装XCache 3.0.1 输入new 回车

出现“Press any key to start...or Press Ctrl+c to cancel“,再次回车确认即可开始安装。

c)、memcached

Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载。它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提供动态、数据库驱动网站的速度。

安装
进入lnmp解压后的目录,执行:./memcached.sh
回车确认后就会自动安装memcache php扩展和memcached。

d)、imageMagick

ImageMagick是一个用于查看、编辑位图文件以及进行图像格式转换的开放源代码软件套装。它可以读取、编辑超过100种图象格式。可用来替换GD库。

安装
进入lnmp解压后的目录,执行:./imageMagick.sh
回车确认后就会自动安装imageMagick。

设置:比如在DiscuzX里设置时路径需要填写:/usr/local/imagemagick/bin/ 并且禁用函数里的exec要去掉才可以正常使用。

技术分享图片 

技术分享图片 

5)、LNMP相关软件目录及文件位置
除去所必须的依赖包,LNMP一键安装包会安装一下软件:
默认安装软件:

· Nginx

· MySQL

· PHP

· PHPMyAdmin

· Zend Optimizer

可选软件:

· PureFTPd(可选)

· Proftpd(可选)

· Apache(可选)

· eAccelerator(可选)

· ionCube(可选)

· imageMagick(可选)

· memcached(可选)

· xcache(可选)

注明可选的为可使用安装脚本自行安装,未注明的为会自动安装。
不一定可选包都适合你,按需安装即可。

 

 

LNMP相关软件安装目录
Nginx 目录: /usr/local/nginx/
MySQL 目录 : /usr/local/mysql/
MySQL数据库所在目录:/usr/local/mysql/var/
PHP目录 : /usr/local/php/
PHPMyAdmin目录 : 0.9版为/home/wwwroot/phpmyadmin/ 1.0版为 /home/wwwroot/default/phpmyadmin/ 强烈建议将此目录重命名为其不容易猜到的名字。phpmyadmin可自己从官网下载新版替换。
默认网站目录 : 0.9版为 /home/wwwroot/ 1.0版为 /home/wwwroot/default/
Nginx日志目录:/home/wwwlogs/
/root/vhost.sh添加的虚拟主机配置文件所在目录:/usr/local/nginx/conf/vhost/-------!!!!!!!!!!!!!!!!!!!!!!!
PureFtpd 目录:/usr/local/pureftpd/
PureFtpd web管理目录: 0.9版为/home/wwwroot/default/ftp/ 1.0版为 /home/wwwroot/default/ftp/
Proftpd 目录:/usr/local/proftpd/

 

查看进程  ps auxw 换行查看进程  

终止进程  pkill  -9  php-fpm

开始进程 [[email protected] selinux]# /root/lnmp start

平滑重启nginx进程 pkill -HUP nginx

 

LNMP相关配置文件位置
Nginx主配置文件:/usr/local/nginx/conf/nginx.conf
/root/vhost.sh添加的虚拟主机配置文件:/usr/local/nginx/conf/vhost/域名.conf
MySQL配置文件:/etc/my.cnf
PHP配置文件:/usr/local/php/etc/php.ini
php-fpm配置文件:/usr/local/php/etc/php-fpm.conf
PureFtpd配置文件:/usr/local/pureftpd/pure-ftpd.conf
PureFtpd MySQL配置文件:/usr/local/pureftpd/pureftpd-mysql.conf
Proftpd配置文件:/usr/local/proftpd/etc/proftpd.conf
Proftpd 用户配置文件:/usr/local/proftpd/etc/vhost/用户名.conf

 

LNMPA相关目录文件位置
Apache目录:/usr/local/apache/
Apache配置文件:/usr/local/apache/conf/httpd.conf
Apache虚拟主机配置文件目录:/usr/local/apache/conf/vhost/

 

6)、LNMP状态管理命令
LNMP状态管理命令:

LNMP状态管理: /root/lnmp start|stop|reload|restart|kill|status
Nginx状态管理:/etc/init.d/nginx start|stop|reload|restart
MySQL状态管理:/etc/init.d/mysql start|stop|restart|reload|force-reload|status
Memcached状态管理:/etc/init.d/memcached start|stop|restart
PHP-FPM状态管理:/etc/init.d/php-fpm start|stop|quit|restart|reload|logrotate
PureFTPd状态管理: /etc/init.d/pureftpd start|stop|restart|kill|status
ProFTPd状态管理: /etc/init.d/proftpd start|stop|restart|reload

如重启LNMP,输入命令:/root/lnmp restart 即可,单独重启mysql:/etc/init.d/mysql restart

 

LNMPA状态管理命令:

LNMPA状态管理: /root/lnmpa start|stop|reload|restart|kill|status
Nginx状态管理:/etc/init.d/nginx start|stop|reload|restart
MySQL状态管理:/etc/init.d/mysql start|stop|restart|reload|force-reload|status
Memcached状态管理:/etc/init.d/memcached start|stop|restart
PureFTPd状态管理: /etc/init.d/pureftpd start|stop|restart|kill|status
ProFTPd状态管理: /etc/init.d/proftpd start|stop|restart|reload
Apache状态管理:/etc/init.d/httpd start|stop|restart|graceful|graceful-stop|configtest|status

 

[[email protected] selinux]# cd /etc/rc.d/init.d------------------快捷方式------一样的效果

[[email protected] init.d]# ls

abrt-ccpp     certmonger  ip6tables     messagebus

Nginx为源码包所装

[[email protected] rc.d]# cd /etc/init.d----------------------------快捷方式--------一样的效果

[[email protected] init.d]# ls

abrt-ccpp     certmonger  ip6tables     messagebus

 

 

4. 修改Nginx配置文件-------不是默认的配置文件 是经过修改优化的配置文件

nginx配置文件的位置:

[[email protected] init.d]# vi  /usr/local/nginx/conf/nginx.conf

user  www www;  ------------伪用户 伪用户组

[[email protected] ~]# cat /etc/passwd | grep www

apache:x:48:48:Apache:/var/www:/sbin/nologin

www:x:508:509::/home/www:/sbin/nologin

Apache的伪用户

[[email protected] ~]# cat /etc/passwd | grep daemon

daemon:x:2:2:daemon:/sbin:/sbin/nologin

avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin

haldaemon:x:68:68:HAL daemon:/:/sbin/nologin


(基本配置)
worker_processes 1; -------单位/个数 一般写为CPU的数量 一般是两个

#启动进程,通常设置成和cpu的数量相等。相当于cpu个数

error_log  logs/nginx_error.log; ---------相对路径--相对于安装位置

#错误日志

pid(进程id       vi /usr/local/nginx/logs/nginx.pid;

[[email protected] ~]# vi /usr/local/nginx/logs/nginx.pid-----1588

root      1588  0.0  0.1   7072   796 ?        Ss   Jul02   0:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

#主进程PID保存文件 --------判断apache是否运行

#Specifies the value for maximum file descriptors that can be opened by this process. 
worker_rlimit_nofile 51200;

#文件描述符数量---------不是最大并发连接数

Unix 系统最大连接并发数

[[email protected] ~]# ulimit -a

max memory size         (kbytes, -m) unlimited

open files                      (-n) 1024  --------打开文件

pipe size            (512 bytes, -p) 8

[[email protected] ~]# ulimit -SHn 65535-------此条命令需要每次开机都执行

[[email protected] ~]# vi /etc/rc.local -------写入开机自启动

#!/bin/sh

# This script will be executed *after* all the other init scripts.

# You can put your own initialization stuff in here if you don‘t

# want to do the full Sys V style init stuff.

 

touch /var/lock/subsys/local

ulimit -SHn 65535

 

open files                      (-n) 65535


events 
   use epoll;

#网络I/O模型,建议linux使用epoll,FreeBSD使用kqueue

#epoll是多路复用IO(I/O Multiplexing)中的一种方式,但是仅用于linux2.6以 上内 核,可以大大提高nginx的性能
   worker_connections 51200;

#单个工作进程最大允许连接数     最大并发连接数


http 

#整体环境配置apach默认配置)

   include       mime.types;(子配置文件)
   default_type  application/octet-stream;
#设定mime类型,文件传送类型由mime.type文件定义

 

                server_names_hash_bucket_size 128; #保存服务器名字的hash表大小

                client_header_buffer_size 32k; #客户端请求头部缓冲区大小

                large_client_header_buffers 4 32k; #最大客户端头缓冲大小

                client_max_body_size 50m; #客户端最大上传文件大小(M)

 

                sendfile on;

#sendfile 指令指定 nginx 是否调用 sendfile 函数(zero copy 方式)来输出文 件,对于普通应用,必须设为 on如果用来进行下载等应用磁盘IO重负载应用,可 设置为off,以平衡磁盘与网络I/O处理速度,降低系统的uptime.

                tcp_nopush     on;

#这个是默认的,结果就是数据包不会马上传送出去,等到数据包最大时,一次性的 传输出去,这样有助于解决网络堵塞。(只在sendfile on时有效)

 

                keepalive_timeout 60;

#连接超时时间

 

                tcp_nodelay on;

#禁用nagle算法,也即不缓存数据。

 

                fastcgi_connect_timeout 300;后台靠它处理数据

                fastcgi_send_timeout 300;

                fastcgi_read_timeout 300;

                fastcgi_buffer_size 64k;

                fastcgi_buffers 4 64k;

                fastcgi_busy_buffers_size 128k;

                fastcgi_temp_file_write_size 256k;

#fastcgi设置

 

                gzip on;

                gzip_min_length  1k;

                gzip_buffers     4 16k;

                gzip_http_version 1.0;

                gzip_comp_level 2;

                gzip_types       text/plain application/x-javascript text/css application/xml;

                gzip_vary on;

                gzip_proxied        expired no-cache no-store private auth;

                gzip_disable        "MSIE [1-6].";

#开启gzip网络压缩

 

                #limit_zone  crawler  $binary_remote_addr  10m;

 

                server_tokens off;

#隐藏客户端页面报错nginx版本号(curl -I 192.168.4.154可以查看,更加安全)

 

                #log format

                log_format  access  ‘$remote_addr - $remote_user [$time_local] "$request" ‘

             ‘$status $body_bytes_sent "$http_referer" ‘

             ‘"$http_user_agent" $http_x_forwarded_for‘;

#定义日志格式

 

Server------每一个server就是一个网站

        

                listen       80;

#监听80端口

                server_name www.lnmp.org;

#服务器名

                index index.html index.htm index.php;

#默认网页文件

                root  /home/wwwroot/default;

#网页主目录

 

                location ~ .*.(php|php5)?$  每一个location都是一个匹配的区域

  技术分享图片

                        

                                try_files $uri =404;

#分析文件是否存在,如果不存在报404错误

                                fastcgi_pass  unix:/tmp/php-cgi.sock;

#指定FastCGI服务器监听端口与地址。这里使用unix socket

#nginx以unix-domain-socket方式连接fastcgi(php)。更快,适合大流量访问

#另外一种 nginx连接fastcgi的方式是http方式的[ 127.0.0.1:9000  方式连接 fastcgi(php)

                                fastcgi_index index.php;

#默认网页文件

                                include fcgi.conf;

#fcgi.conf配置文件生效

                        

 

                location /status   -----------/不可省略

  技术分享图片

                        stub_status on;

                        access_log   off;

                

#开启status状态监测----监控服务器时使用

 

                location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$

                        

                                expires      30d;    ---缓存30天

                        

#静态文件处理,保存期30天

 

                location ~ .*.(js|css)?$

                        

                                expires      12h;

                        

#匹配js和css文件处理,保存期12小时

 

                access_log  /home/wwwlogs/access.log  access;日志格式 调用前面的日志格式

#正确访问日志

        

include vhost/*.conf;

#vhost/下子配置文件生效

 

 

5.配置开机启动nginx,php-fpm,ulimit

1)nginx

Vi /etc/rc.local

/usr/local/nginx/sbin/nginx

2)php-fpm

Vi /etc/rc.local

/usr/local/php/sbin/php-fpm start

3)ulimit

Vi /etc/rc.local

ulimit -SHn 65535   ----------

4)mysql

Vi /etc/rc.local

/usr/local/mysql/bin/mysqld_safe  --user=mysql  &

 

一键安装包已经完成自启动,加入了chkconfig管理,可以直接使用service命令和chkconfig命令管理

已经自动加入了开机自启动 不需要在/etc/rc.local里面再次写入!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

使用chkconfig 做的开机自启动

查看:

[[email protected] init.d]# chkconfig --list | grep nginx

nginx           0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭

[[email protected] init.d]# chkconfig --list | grep php-fpm

php-fpm         0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭

[[email protected] init.d]#  

 

6.检查nginx配置文件语句错误

/usr/local/nginx/sbin/nginx -t

[[email protected] ~]# /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

[[email protected] ~]#

 

7.平滑重启nginx进程------先重启没有访问的进程 让客户端感觉不到

1)pkill -HUP nginx

2)kill -HUP `pgrep -uroot nginx`

   Pgrep  -uroot  nginx  取出nginx主进程PID

3)/usr/local/nginx/sbin/nginx -s reload

技术分享图片 


8.配置nginx虚拟主机

 

Sina和sohu域名事先解析

 

Vi /usr/local/nginx/conf/nginx.conf

==èwww.sina.com公司网站

server

        

                listen       80;

                server_name www.sina.com;

                index index.html index.htm index.php;

                root  /home/wwwroot/sina;

 

                location ~ .*.(php|php5)?$

                        

                                try_files $uri =404;

                                fastcgi_pass  unix:/tmp/php-cgi.sock;

                                fastcgi_index index.php;

                                include fcgi.conf;

                        

 

==èwww.sohu.com公司网站

 

server

        

                listen       80;

                server_name www.sohu.com;

                index index.html index.htm index.php;

                root  /home/wwwroot/sohu;

 

                location ~ .*.(php|php5)?$

                        

                                try_files $uri =404;

                                fastcgi_pass  unix:/tmp/php-cgi.sock;

                                fastcgi_index index.php;

                                include fcgi.conf;

                        

        

重启nginx

最后在客户端测试虚拟主机www.baidu.com和www.sina.com两家公司网站

[[email protected] ~]# mkdir /home/wwwroot/sina

[[email protected] ~]# mkdir /home/wwwroot/sohu

[[email protected] ~]# vi /home/wwwroot/sina/index.html     sina

[[email protected] ~]# vi /home/wwwroot/sohu/index.html    sohu

[[email protected] ~]# pkill -HUP nginx

[[email protected] ~]#

技术分享图片技术分享图片 

 

9.列表页显示

server

        

                listen       80;

                server_name www.sina.com;

                index index.html index.htm index.php;

                root  /home/wwwroot/sina;

                autoindex on;     --------------------------apache的index权限

 技术分享图片

加入 autoindex on; 

技术分享图片 

!pkill 调用最后一个以此字符串开头的命令

[[email protected] sina]# !pkill

pkill -HUP nginx

[[email protected] sina]#

 

 

10.nginx状态监控

location /nginxstatus

        stub_status on;

        access_log  off;

        

#客户端访问网址:http://IP/nginxstatus

 

11.rewrite正则过滤

location ~ .php$

        proxy_pass   http://127.0.0.1;

        

Rewrite指令最后一项参数为flag标记,支持的flag标记如下:

Last(文件跳转)

停止执行当前这一轮的ngx_http_rewrite_module指令集,然后查找匹配改变后URI的新location;

Break

停止执行当前这一轮的ngx_http_rewrite_module指令集;

Redirect

在replacement字符串未以“http://”或“https://”开头时,使用返回状态码为302的临时重定向;

Permanent(域名跳转)

返回状态码为301的永久重定向。

 

Last和break用来实现uri重写,浏览器地址栏的url地址不变,但在服务器访问的路径发生了变化,redirect和permanent用来实现url跳转,浏览器地址栏会显示跳转后的url地址,使用alias指令时必须使用last标记,使用proxy_pass指令时要使用break标记,last标记在本条rewrite规则执行完毕后,会对其所在的server标签重新发起请求,而break标记则在本条规则匹配完成后,终止匹配,不再匹配后面的规则.

 

 

例1:域名跳转

输入www.sina.com,跳转到www.sohu.com

server

        

                listen       80;

                server_name www.sina.com;

                index index.html index.htm index.php;

                root  /home/wwwroot/sina;

 

                if ($http_host = www.sina.com)

                        rewrite  (.*)  http://www.sohu.com  permanent;(标记)

                

 

                location ~ .*.(php|php5)?$

                        

                                try_files $uri =404;

                                fastcgi_pass  unix:/tmp/php-cgi.sock;

                                fastcgi_index index.php;

                                include fcgi.conf;

                        

 

server

        

                listen       80;

                server_name www.sohu.com;

                index index.html index.htm index.php;

                root  /home/wwwroot/sohu;

 

                location ~ .*.(php|php5)?$

                        

                                try_files $uri =404;

                                fastcgi_pass  unix:/tmp/php-cgi.sock;

                                fastcgi_index index.php;

                                include fcgi.conf;

                        

        

 

例2:文件跳转

server

        

                listen       80;

                server_name www.sina.com;

                index index.html index.htm index.php;

                root  /home/wwwroot/sina;

 

                rewrite inde /indexa.html last;

 

                location ~ .*.(php|php5)?$

                        

                                try_files $uri =404;

                                fastcgi_pass  unix:/tmp/php-cgi.sock;

                                fastcgi_index index.php;

                                include fcgi.conf;

                        

 

12.代理负载均衡技术(反向代理)

技术分享图片 

如果是unix 使用squid+其他支持 搭建

 

http

        

upstream myweb1

#定义地址池

        server 192.168.244.10:80;

        server 192.168.244.11:80;

    server

        listen       80;

        server_name  www.sohu.com;

#使用www.sohu.com访问

location /

proxy_pass http://myweb1; --------------------把所有的apache请求转发给web服务器

#使用地址池

proxy_set_header Host $host;

#利用HOST变量向后端服务器传递需要解析的客户端访问的域名(传递域名)

proxy_set_header X-Forwarded-For $remote_addr;

#$remote_addr 把客户端真实IP赋予X-Forwarded-For。后端服务器才能获取真实的客户端IP。以便记录日志,要不日志中记录的访问信息都是负载服务器,而不是客户端(传递IP)

技术分享图片 

正常:客户端-->请求---->反向代理服务器122 ->web服务器 请求非常小

正常:web服务器-->响应--->反向代理服务器-->(大数据回来响应)->宕机

加上以上两句话的作用是当用户输入域名访问的时候 反向代理服务器接收域名的同时把客户端得ip传给web服务器   web服务器响应的时候就会通过客户端的ip绕过反向代理服务器 直接去响应客户端  避免了反向服务器的宕机

 

技术分享图片 

1.所有的server删掉

2.定义地址池 放入http内部

3.定义访问网站 以及location配置

4.web服务器的数据库1、2是可以实现同步更新的(主从备份、主主备份)

 


























































































lnmp架构搭建与优化

安装MySQL安装PHP安装Nginx解析PHPNginx启动脚本Nginx配置文件Nginx502问题php-fpm配置文件Nginx配置默认虚拟主机        查看详情

centos下lnmp环境配置(代码片段)

安装配置Nginx安装配置MySQL安装配置PHPNginx与PHP-FPM集成环境配置验证 LNMP环境代表Linux系统下Nginx+MySQL+PHP网站服务器架构。本文档介绍CentOS下的LNMP环境搭建。本文档包含软件安装内容,请确保您已熟悉软件安装方法.。安装配置... 查看详情

lnmp的配置与优化

一、LNMP的下载LNMP一键安装包是一个用LinuxShell编写的可以为CentOS/RadHat/Fedora、Debian/Ubuntu/Raspbian/DeepinVPS或独立主机安装LNMP(Nginx/MySQL/PHP)、LNMPA(Nginx/MySQL/PHP/Apache)、LAMP(Apache/MySQL/PHP)生产环境的Shell程序。同时提供一些实用的辅助工具... 查看详情

lnmp

安装yasm安装libmcrypt安装libvpx安装Tiff安装libpng安装freetype安装jpeg安装libgd安装t1lib将函数库文件放至合适的位置安装php复制php的配置文件到安装目录:删除默认的php创建php配置文件编辑php//将第25行参数前面的分号去掉pid=run/php-fpm.p... 查看详情

部署lnmp架构(代码片段)

部署LNMP架构文章目录部署LNMP架构1、nginx的安装与配置1、1nginx的安装1、2nginx安装后配置2、部署mysql2、1关闭防火墙和selinux2、2解压mysql压缩包2、3安装后配置3、部署php3、1下载并解压PHP压缩包3、2安装后配置3、3配置php-fpm3、4启动p... 查看详情

lnmp安装配置

LNMP安装配置目录bin:存放普通用户可执行命令sbin:存放超级用户可执行命令whichiptables:查看boot目录:存放系统启动所需(内核,映像)dev:设备文件(鼠标,键盘...等外部设备)etc:配置文件home:家目录:1.普通用户家目录2.... 查看详情

lnmp环境部署

...境,区别主要在nginx与PHP协作配置上一:部署nginx服务1)安装支持软件Nginx配置运行需要pcre,zlib等软件包支持,因此预先安装这些软件的开发包,以提供相应库和文件,确保Nginx顺利完成[[email protected] /]# yum -y&nbs 查看详情

ubuntu安装配置lnmp

Ubuntu-15.04安装配置LNMP服务一、操作系统版本信息[email protected]:~#lsb_release-aNoLSBmodulesareavailable.DistributorID:UbuntuDescription:   Ubuntu14.04.4LTSRelease:   14.04Codename 查看详情

chapterone:安装配置lnmp

源码安装配置LNMP更新时间:2016-08-02系统环境:CentOS6.5软件环境:nginx1.8.1、mysql5.6.22、php5.6.19本机IP :192.168.1.88、192.168.1.36关闭防火墙和安全机制#serviceiptablesstop#setenforce0#getenforce【nginx】1.创建用户#groupaddnginx#useradd 查看详情

lnmp一键安装包配置https(代码片段)

一、安装包安装大家按照官方说的安装即可。./install.shlnmpa二、配置为域名bbs.wzlinux.com配置虚拟主机[[email protected]~]#lnmpvhostadd+-------------------------------------------+|ManagerforLNMP,WrittenbyLicess|+------------------- 查看详情

lnmp架构搭建与优化

1,1php编译与安装LAMPapache、mysql、phpLNMPnginx、mysql、phpmysql的安装与LAMP的mysql安装方法一样先安装mysql再安装phpcd/usr/local/srcwgethttp://cn2.php.net/distributions/php-5.4.37.tar.bz2 下载tarjxvfphp-5.4.37.tar.bz2解压cdphp 查看详情

lnmp环境的搭建与配置(二)

...用Xshell登录到云服务器。完成第二部分,你基本基本已经安装成功LNMP环境了,在安装过程中,可能会遇到一些问题,可以百度搜索下,或者可以在评论区留言。安装完成LNMP环境后,接下来要做的就是为你的服务器添加网站了。... 查看详情

ubuntu系统lnmp环境下安装配置zabbix3.0

Ubuntu14.04(LNMP)安装配置Zabbix3.0,LNMP安装你可以参考我上一篇博文《ubuntu安装配置LNMP》添加zabbix3.0的源可以根据自己工作需求选择zabbix版本# wgethttp://repo.zabbix.com/zabbix/3.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_3.0-1+tru 查看详情

lnmp安装ftp服务并配置ftp用户

lnmp默认是不带FTP服务的,需要的童鞋要自行安装.步骤也很简单一,进入lnmp目录,找到pureftpd.sh二,直接运行该脚本 ./pureftpd.sh按任意键开始安装,等待,安装成功如下可以使用以下命令服务lnmpftpadd添加FTPlnmpftplist显示FTP用户lnmpftpdel... 查看详情

lnmp环境搭建

LNMP环境1.安装Linux操作系统(略)2.安装Mysql(1)下载所需的安装包(2)执行安装(3)启动服务(4)查看进程并修改密码3.安装php(1)创建用户(2)安装所需的依赖包(3)解压(4)配置编译程序(5)编译并安装php(6)修改配... 查看详情

lnmp安装目录及配置文件位置

LNMP相关软件安装目录Nginx目录:/usr/local/nginx/MySQL目录:/usr/local/mysql/MySQL数据库所在目录:/usr/local/mysql/var/MariaDB目录:/usr/local/mariadb/MariaDB数据库所在目录:/usr/local/mariadb/var/PHP目录:/usr/local/php/PHPMyAdmin目录:0.9 查看详情

lnmp安装配置

一、总体简介Lnmp架构(Linux+nginx+mysql+php)是目前网站的主流架构,这个架构包含了一个网站的最基本要求:运行环境+web容器+动态页面处理+存储。当然同样主流的架构还有lamp,但是个人认为nginx的性能在现在的趋势下更胜一筹... 查看详情

基于centos的lnmp搭建

部署lnmp环境安装配置mariadb配置php配置phpmyadmin配置php-fpm配置nginx配置测试LNMP(linux,nginx,mariadb,php)部署,以下默认在root权限下操作,以centos7为例。安装安装nmp(nginx-mariadb-php)yuminstallnginxmariadb-serverphpphp-fpm设置开机启动并立即启... 查看详情