热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

centos6.1安装配置nginx和php

CentOS6.1环境中部署nginx、php(包括fastcgi)、虚拟主机配置,需要的朋友可以参考下部署时间:2012-07-24OS环境:CentOS6.1nginx:nginx-1.2.2PHP:PHP5.3.140、安装依赖包yuminstallopenssl-develpcre-develzlib-deve

CentOS 6.1 环境中部署nginx、php(包括fastcgi)、虚拟主机配置,需要的朋友可以参考下

部署时间:2012-07-24
OS环境:CentOS 6.1
nginx:nginx-1.2.2
PHP:PHP5.3.14
0、安装依赖包

yum install openssl-devel pcre-devel zlib-devel libjpeg-devel libpng-devel freetype-devel gcc make

1、添加 www 用户用来执行nginx

useradd -M -r -s /sbin/nologin -d /opt/web/ www

2、创建临时目录 mkdir -p /var/tmp/nginx/client/
mkdir -p /var/tmp/nginx/proxy/
mkdir -p /var/tmp/nginx/fcgi/
3、下载nginx最新稳定版源代码 cd /usr/local/src/
wget http://nginx.org/download/nginx-1.2.2.tar.gz
4、解压,编译,安装 tar vxzf nginx-1.2.2.tar.gz
cd nginx-1.2.2/
./configure \
--prefix=/opt/web/nginx \
--error-log-path=/var/log/nginx/error.log \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--user=www \
--group=www \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--http-log-path=/var/log/nginx/access.log \
--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/
make
make install
5、配置nginx vim /opt/web/nginx/conf/nginx.conf
# 指定启动用户:
user www www;
# 进程数量,nginx作者认为一个就可以,根据自己的访问量修改
worker_processes 1;
# 设置错误日志:
#error_log logs/error.log notice;
#error_log logs/error.log info;
error_log /var/log/nginx/error.default.log;
pid /opt/web/nginx/nginx.pid;
events {
use epoll;
worker_connections 1024;
}
http {
charset utf-8;
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;
tcp_nodelay on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
gzip_min_length 1000;
gzip_proxied any;
gzip_types text/plain text/css text/xml
application/x-Javascript application/xml
application/atom+xml text/Javascript;
server {
listen 80;
server_name localhost;
charset utf-8;
#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;
include fastcgi.conf;
}
# 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;
# server_name localhost;
# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_timeout 5m;
# ssl_protocols SSLv2 SSLv3 TLSv1;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
proxy_read_timeout 200;
# Only retry if there was a communication error, not a timeout
# on the Tornado server (to avoid propagating "queries of death"
# to all frontends)
proxy_next_upstream error;
proxy_set_header X-Scheme $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# 引入虚拟主机文件
include /opt/web/nginx/conf/sites/*.conf;
}
6、建立虚拟机配置文件存放的目录

mkdir /opt/web/nginx/conf/sites

这样配置后,需要新增加虚拟主机的直接在 nginx/conf/sites/目录下,添加配置文件即可
例如:现在有 www.server110.com 域名
建立:/opt/web/nginx/conf/sites/www.server110.com.conf 文件
内容如下: server {
listen 80;
client_max_body_size 10M;
#多个域名用空格分割,第一个为默认
server_name www.server110.com server110.com;
charset UTF-8;
index index.html index.htm index.php;
# 定义根目录
set $root /var/webroot/www.server110.com/;
# 设置站点路径
root $root;
# 防止目录浏览
autoindex off;
if ($host != 'www.server110.com') {
rewrite ^/(.*)$ http://www.server110.com/$1 permanent;
}
# 防止.htaccess文件被请求
location ~ /\.ht {
deny all;
}
error_page 404 /404.html;
index index.html index.htm;
location /uploads/ {
alias /data/webroot/www.server110.com/uploads/;
}
try_files $uri @uwsgi;
location @uwsgi{
# 将其它的请求转交给uwsgi
include uwsgi_params;
uwsgi_pass unix:/tmp/360ito_uwsgi.sock;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#proxy_pass http://localhost:5000;
}
# 将php类型的请求转交给fastcgi
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
# 访问日志:
access_log /var/log/nginx/access.www.server110.com.log;
# 加载.htaccess重写文件,注意,这里不支持变量路径
# 不能写成 include $root/www.server110.com/.htaccess;
# include /var/webroot/www.server110.com/.htaccess;
# 开启域名跳转,则当访问出错后,其他域名会自动跳转到 www.server110.com
# 注意,这里我说的是,仅仅当访问出错后,才会跳转,所以,这里并不能实现301重定向!
server_name_in_redirect on;
}
7、安装最新版本PHP( PHP5.3.14 ) cd /usr/local/src/
wget http://cn.php.net/get/php-5.3.14.tar.bz2/from/this/mirror
tar xjvf php-5.3.14.tar.bz2
cd php-5.3.14
执行:

./buildconf --force

如果报错,可能是你的 autoconf不是 2.13 版本的,PHP5.3.系列的bug,需要安装 autoconf为2.13的版本: CentOS : # yum install autoconf213
Debian : # apt-get install autoconf2.13
设置环境变量 # CentOS :
export PHP_AUTOCOnF="/usr/bin/autoconf-2.13"
# Debian :
export PHP_AUTOCOnF="/usr/bin/autoconf2.13"
再次运行:./buildconf --force ,出现 buildconf: autoconf version 2.13 (ok)
,则表示成功。
编译安装 PHP ./configure \
--prefix=/opt/web/php \
--with-config-file-path=/opt/web/php/etc \
--with-config-file-scan-dir=/opt/web/php/etc/conf.d \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--with-mysql=/opt/db/Percona-Server-5.5.14-rel20.5 \
--with-mysqli=/opt/db/Percona-Server-5.5.14-rel20.5/bin/mysql_config \
--with-iconv-dir \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir \
--enable-xml \
--enable-mbstring \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--enable-inline-optimization
make && make install
cp php.ini-production /opt/web/php/etc/php.ini
cd /opt/web/php/etc
cp php-fpm.conf.default php-fpm.conf
修改php-fpm.conf 启用如下几行,即去掉前面的分号(;) pid = run/php-fpm.pid
error_log = log/php-fpm.log
log_level = notice
listen = 127.0.0.1:9000
listen.allowed_clients = 127.0.0.1
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
8、启动php-fpm

/opt/web/php/sbin/php-fpm

启动nginx

/opt/web/nginx/sbin/nginx

9、测试一下

vim /var/webroot/www.server110.com/tz.php

输入和保存 phpinfo();
?>
10、在浏览器地址栏输入:http://www.server110.com/tz.php
成功的话,可以看到phpinfo()输出的信息
推荐阅读
  • 本文讨论了Alink回归预测的不完善问题,指出目前主要针对Python做案例,对其他语言支持不足。同时介绍了pom.xml文件的基本结构和使用方法,以及Maven的相关知识。最后,对Alink回归预测的未来发展提出了期待。 ... [详细]
  • CentOS 7部署KVM虚拟化环境之一架构介绍
    本文介绍了CentOS 7部署KVM虚拟化环境的架构,详细解释了虚拟化技术的概念和原理,包括全虚拟化和半虚拟化。同时介绍了虚拟机的概念和虚拟化软件的作用。 ... [详细]
  • CentOS 6.5安装VMware Tools及共享文件夹显示问题解决方法
    本文介绍了在CentOS 6.5上安装VMware Tools及解决共享文件夹显示问题的方法。包括清空CD/DVD使用的ISO镜像文件、创建挂载目录、改变光驱设备的读写权限等步骤。最后给出了拷贝解压VMware Tools的操作。 ... [详细]
  • 本文介绍了OC学习笔记中的@property和@synthesize,包括属性的定义和合成的使用方法。通过示例代码详细讲解了@property和@synthesize的作用和用法。 ... [详细]
  • Mac OS 升级到11.2.2 Eclipse打不开了,报错Failed to create the Java Virtual Machine
    本文介绍了在Mac OS升级到11.2.2版本后,使用Eclipse打开时出现报错Failed to create the Java Virtual Machine的问题,并提供了解决方法。 ... [详细]
  • 在说Hibernate映射前,我们先来了解下对象关系映射ORM。ORM的实现思想就是将关系数据库中表的数据映射成对象,以对象的形式展现。这样开发人员就可以把对数据库的操作转化为对 ... [详细]
  • 本文介绍了在SpringBoot中集成thymeleaf前端模版的配置步骤,包括在application.properties配置文件中添加thymeleaf的配置信息,引入thymeleaf的jar包,以及创建PageController并添加index方法。 ... [详细]
  • 知识图谱——机器大脑中的知识库
    本文介绍了知识图谱在机器大脑中的应用,以及搜索引擎在知识图谱方面的发展。以谷歌知识图谱为例,说明了知识图谱的智能化特点。通过搜索引擎用户可以获取更加智能化的答案,如搜索关键词"Marie Curie",会得到居里夫人的详细信息以及与之相关的历史人物。知识图谱的出现引起了搜索引擎行业的变革,不仅美国的微软必应,中国的百度、搜狗等搜索引擎公司也纷纷推出了自己的知识图谱。 ... [详细]
  • 本文讲述了作者通过点火测试男友的性格和承受能力,以考验婚姻问题。作者故意不安慰男友并再次点火,观察他的反应。这个行为是善意的玩人,旨在了解男友的性格和避免婚姻问题。 ... [详细]
  • 本文详细介绍了Linux中进程控制块PCBtask_struct结构体的结构和作用,包括进程状态、进程号、待处理信号、进程地址空间、调度标志、锁深度、基本时间片、调度策略以及内存管理信息等方面的内容。阅读本文可以更加深入地了解Linux进程管理的原理和机制。 ... [详细]
  • Voicewo在线语音识别转换jQuery插件的特点和示例
    本文介绍了一款名为Voicewo的在线语音识别转换jQuery插件,该插件具有快速、架构、风格、扩展和兼容等特点,适合在互联网应用中使用。同时还提供了一个快速示例供开发人员参考。 ... [详细]
  • 1,关于死锁的理解死锁,我们可以简单的理解为是两个线程同时使用同一资源,两个线程又得不到相应的资源而造成永无相互等待的情况。 2,模拟死锁背景介绍:我们创建一个朋友 ... [详细]
  • 后台获取视图对应的字符串
    1.帮助类后台获取视图对应的字符串publicclassViewHelper{将View输出为字符串(注:不会执行对应的ac ... [详细]
  • 《数据结构》学习笔记3——串匹配算法性能评估
    本文主要讨论串匹配算法的性能评估,包括模式匹配、字符种类数量、算法复杂度等内容。通过借助C++中的头文件和库,可以实现对串的匹配操作。其中蛮力算法的复杂度为O(m*n),通过随机取出长度为m的子串作为模式P,在文本T中进行匹配,统计平均复杂度。对于成功和失败的匹配分别进行测试,分析其平均复杂度。详情请参考相关学习资源。 ... [详细]
  • 本文介绍了通过ABAP开发往外网发邮件的需求,并提供了配置和代码整理的资料。其中包括了配置SAP邮件服务器的步骤和ABAP写发送邮件代码的过程。通过RZ10配置参数和icm/server_port_1的设定,可以实现向Sap User和外部邮件发送邮件的功能。希望对需要的开发人员有帮助。摘要长度:184字。 ... [详细]
author-avatar
HK12593
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有