在rhel6 64位环境下部署LNMP环境

news/2024/7/4 9:41:33

实验目的:应用Nginx网页服务器,掌握LNMP基本架构
实验前提:此实验除Nginx和php需要重新编译外,其他相关软件与LAMP安装方式相同,故删除之前LAMP架构中的Apache和PHP,编译安装Nginx和PHP
实验环境:RHEL61_64 nginx-1.0.9 php-5.2.17
内核版本:2.6.32-131.0.15.el6.x86_64
实验步骤:
1.Nginx-1.0.9 编译安装
./configure --prefix=/usr/local/nginx --user=daemon --group=daemon --with-rtsig_module --with-select_module --with-poll_module
--with-file-aio --with-http_ssl_module --with-http_realip_module
--with-http_addition_module --with-http_image_filter_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nignx/nginx.pid --http-client-body-temp-path=/tmp/nginx_http --http-proxy-temp-path=/tmp/nginx_proxy --http-fastcgi-temp-path=/tmp/nginx_fcgi --with-cpu-opt=pentium4 --without-http_uwsgi_module --without-http_scgi_module --with-http_stub_status_module --with-http_perl_module --with-perl=/usr/bin/perl --with-perl_modules_path=/usr/share/perl5 --with-pcre

检查安装时会显示:
nginx path prefix: "/usr/local/nginx" ----nginx安装路径
nginx binary file: "/usr/local/nginx/sbin/nginx" ----nginx启动脚本
nginx configuration prefix: "/usr/local/nginx/conf" ----nginx配置文件所在位置
nginx configuration file: "/usr/local/nginx/conf/nginx.conf" ----nginx配置文件
nginx pid file: "/var/run/nignx/nginx.pid"
nginx error log file: "/var/log/nginx/error.log"
nginx http access log file: "/var/log/nginx/access.log"
nginx http client request body temporary files: "/tmp/nginx"
nginx http proxy temporary files: "/tmp/nginx"
nginx http fastcgi temporary files: "/tmp/nginx"
apache和nginx通信机制对比:
apache --> mod_libphp5.so --> /usr/local/bin/php --> php.ini -> socket -> mysql
nginx --> tcp/ip -> /usr/local/bin/php-fcgi -> php.ini -> tcp/ip -> mysql
nginx简单配置:
vim /usr/local/nginx/conf/nginx.conf
user daemon;
worker_processes 5; 打开的进程数量
error_log /var/log/nginx/error.log info;
pid /var/run/nginx/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 /var/log/nginx/access.log main;
sendfile on; 允许文件上传
keepalive_timeout 65;

server { 
listen 80;
server_name www.cluster.com;
charset gb2312;
access_log /var/log/nginx/www.access.log main;
location / {
root /www;
index index.html index.htm index.php;
}
error_page 500 502 503 504 /50x.html; 定义错误代码
location = /50x.html {
root html;
}

}

检查nginx.conf配置文件是否有语法错误
[root@station10 nginx-1.0.9]# /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

[root@station10 nginx-1.0.9]# /usr/local/nginx/sbin/nginx <- 启动服务器
[root@station10 nginx-1.0.9]# /usr/local/nginx/sbin/nginx -s stop <- 关闭服务器
2.编译安装php-5.2.17
./configure --enable-fastcgi --enable-force-cgi-redirect --disable-ipv6 --with-libxml-dir=/usr --with-openssl --with-zlib --with-bz2
--enable-calendar --with-curl --with-curlwrappers --with-pcre-dir=/usr/local --enable-ftp --with-gd=/usr/local
--with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-xpm-dir --with-freetype-dir=/usr/local --enable-gd-native-ttf
--enable-gd-jis-conv --enable-mbstring --with-mcrypt=/usr/local --with-mhash=/usr/local --with-mysql=/usr/local/mysql
--with-mysql-sock=/var/run/mysqld/mysql5.socket --with-mysqli=/usr/local/mysql/bin/mysql_config --with-ncurses=/usr
--with-snmp=/usr --enable-zip --enable-sockets

编译之后会生成/usr/local/bin/php-cgi 此为连接nginx和php的工具

一般情况下并发访问不大的时候:
启动 tcp ->开启9000端口,用于连接nginx和php
/usr/local/bin/php-cgi -b 127.0.0.1:9000 -c /usr/local/lib/php.ini -a &

在虚拟主机中增加
location ~ \.php$ {
root /www;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /www$fastcgi_script_name;
include fastcgi_params;
}

接下来重启nginx,就可以支持php,php与mysql的连接通过php.ini定义mysql的socket来实现
注意:
当并发访问非常大的时候,此时/usr/local/bin/php-cgi就会由于压力而死掉,但nginx可能还会正常工作,
依然能解释静态页面,而php页面将不被解析!
解决方法:
为保持php的稳定性,使用spawn-fcgi-1.6.3.tar.gz产蛋工具,可以解决此问题

spawn-fcgi-1.6.3.tar.gz
./configure --enable-extra-warnings&& make && make install

/usr/local/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 200 -f /usr/local/bin/php-cgi -u daemon -g daemon
\-将会生成200个/usr/local/bin/php-cgi后台进程


本文转自    geekwolf   51CTO博客,原文链接:

http://blog.51cto.com/linuxgeek/995228


http://www.niftyadmin.cn/n/2751577.html

相关文章

Android如何使用WebView访问https的网站

Android中可以用WebView来访问http和https的网站&#xff0c;但是默认访问https网站时&#xff0c;假如证书不被Android承认&#xff0c;会出现空白页面&#xff0c;且不会有任何提示信息&#xff0c;这时我们必须加多一些配置。 此方法只针对2.1版本以上的Android。 package m…

linux 用户行为审计

根据公司需求&#xff0c;整理了一个linux用户审计的脚本&#xff0c;现和大家分享&#xff01; 具体步骤如下&#xff1a; 一&#xff1a;配置调试 1.创建用户审计文件存放目录和审计日志文件 &#xff1b; mkdir -p /var/log/usermonitor/ 2.创建用户审计日志文件&#xff…

tensorflow 损失函数概念和公式

https://zhuanlan.zhihu.com/p/45200767

卸载sublime text在右键菜单中的残留

今天菜鸟强迫症犯了&#xff0c;心里想着&#xff0c;我sublime text都删了不知道几百年了&#xff0c;它怎么还在我的右键菜单里ε( o&#xff40;ω′)ノ 菜鸟自己百度&#xff0c;发现根本就无法解决&#xff0c;最后还是在看了别人写的易语言代码后&#xff0c;恍然大悟&a…

python——代码质量改善(1)

在计算机科学领域&#xff0c;有一句著名的格言&#xff08;俏皮话&#xff09;&#xff1a; There are only two hard things in Computer Science: cache invalidation and naming things. 在计算机科学领域只有两件难事&#xff1a;缓存过期 和 给东西起名字 -- Phil Karlto…

如何改变element-ui中table的样式

有写时候样式写完&#xff0c;需要重新给框架的样式进行覆盖&#xff0c;以便达到我们自己设定的样式&#xff0c;这种样式的覆盖有时候非常麻烦&#xff0c;但是你找到方法了&#xff0c;就会很快。 // 设置el-table的样式 .el-table{ .el-table__header-wrapper{ // .paddin…

idea maven查看版本冲突

2019独角兽企业重金招聘Python工程师标准>>> 基于Maven依赖创建的Spring项目&#xff0c;经常会引入多方的依赖JAR包&#xff0c;而多方的依赖JAR包中也会依赖其它相关的JAR包&#xff0c;很容易造成JAR包之间冲突。 解决的工具 Maven Helper&#xff1a; 1、在idea…

73.fileter表案例,NAT表的应用

fileter表案例 要求如下&#xff1a; 只针对filter表&#xff0c;预设策略INPUT链DROP&#xff0c;其他两个链ACCEPT&#xff0c;然后针对192.168.204.0/24开通22端口&#xff0c;对所有网段开放80端口&#xff0c;对所有网段开放21端口。 这个需求不算复杂&#xff0c;但是因为…