2013-12-30 09:34:01
来 源
ITJS.CN
Linux Apache配置
本文介绍CentOS6.5配置Nginx处理前端Apache处理后端,希望对于初学Nginx服务器相关的朋友有帮助,更多Nginx安装、配置、报错处理等资源请本站内搜索。。

1、配置EPEL YUM源

rpm -ivh http://mirrors.yun-idc.com/epel/6/x86_64/epel-release-6-8.noarch.rpm

2、检查是否安装成功

ll /etc/yum.repos.d/

3、安装nginx并配置

yum -y install nginx

检查:whereis nginx

说明:配置文件在/etc/nginx目录下,主配置文件是/etc/nginx/nginx.conf

(配置前先备份)

cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak

vi /etc/nginx/nginx.conf

修改如下内容(参考nginx配置文件详解)

worker_processes 4;

tcp_nopush on;

server_tokens off;

cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/test.conf

说明:/etc/nginx/conf.d/中conf文件结尾的都会自动加载的

vi /etc/nginx/conf.d/test.conf

#具体说明参考(nginx虚拟主机配置)

server {

listen 80;

server_name 192.168.1.187;

root /var/www/html;

location ~ .*.(php)$ {

proxy_pass http://127.0.0.1:8080;

}

location ~ /.ht {

deny all;

}

}

}

#具体说明参考(nginx虚拟主机配置)

vi /etc/nginx/conf.d/proxy.conf

proxy_redirect off;

proxy_hide_header Vary;

proxy_set_header Accept-Encoding ”;

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

client_max_body_size 10m;

client_body_buffer_size 128k;

client_body_temp_path /tmp;#第一次上传文件总是出错,结果发现是这里的问题!

proxy_connect_timeout 90;

proxy_send_timeout 90;

proxy_read_timeout 90;

proxy_buffer_size 4k;

proxy_buffers 32 4k;

proxy_busy_buffers_size 64k;

#具体说明参考(nginx虚拟主机配置)

gzip on;

gzip_http_version 1.1;

gzip_comp_level 3;

gzip_proxied any;

gzip_vary on;

gzip_buffers 4 16k;

gzip_min_length 1100;

gzip_types text/plain text/css application/xml application/xhtml+xml application/rss+xml application/atom_xml application/javascript application/x-javascript;

4、安装apache并配置

#如果已经安装apache请跳过安装

yum -y install httpd

(修改配置前请备份文件)

cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bak

vi /etc/httpd/conf/httpd.conf

Listen 80改成Listen 8080

DocumentRoot “/var/www/html”修改成你网站根目录(建议建立虚拟主机)

ServerSignature On改成ServerSignature Off

AllowOverride None改成 AllowOverride All

ServerTokens OS改为ServerTokens Prod

#NameVirtualHost *:80修改为NameVirtualHost *:8080(注意去掉#)

Include conf.d/*.conf#注意这里是加载conf.d目录配置文件

5、建立虚拟主机(这里为了统一管理也建立在test.conf中)

vi /etc/httpd/conf.d/test.conf

<VirtualHost *:8080>

DocumentRoot /var/www/html

ServerName 192.168.1.187

ErrorLog logs/test-error_log

CustomLog logs/test-access_log common

</VirtualHost>

6、检查配置文件

httpd -t

httpd: Could not reliably determine the server’s fully qualified domain name, using localhost.localdomain for ServerName

这样的警告解决办法是:vi /etc/httpd/conf/httpd.conf

ServerName localhost

nginx -t

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok

nginx: configuration file /etc/nginx/nginx.conf test is successful

httpd -t

Syntax OK

7、这里就省去PHP和Mysql的安装了,直接进入测试

查看防火墙是否关闭 iptables -L(如果没有关闭使用service iptables stop)

启动nginx和apache

service nginx start

service httpd start

vi /var/www/html/index.php内容为

<?php

$i = 20;

echo $i;

8、框架是否能用呢?(这里测试zend Framework框架)

Fatal error: Uncaught exception ‘Zend_Db_Adapter_Exception’ with message ‘The PDO extension is required for this adapter but the extension is not loaded’ in /var/www/library/Zend/Db/Adapter/Pdo/Abstract.php:342 Stack trace: #0 /var/www/library/Zend/Db/Adapter/Abstract.php(247): Zend_Db_Adapter_Pdo_Abstract->setFetchMode(2) #1 /var/www/library/Zend/Db.php(270): Zend_Db_Adapter_Abstract->__construct(Array) #2 /var/www/library/Zend/Application/Resource/Db.php(142): Zend_Db::factory(‘PDO_MYSQL’, Array) #3 /var/www/library/Zend/Application/Resource/Db.php(154): Zend_Application_Resource_Db->getDbAdapter() #4 /var/www/library/Zend/Application/Bootstrap/BootstrapAbstract.php(683): Zend_Application_Resource_Db->init() #5 /var/www/library/Zend/Application/Bootstrap/BootstrapAbstract.php(626): Zend_Application_Bootstrap_BootstrapAbstract->_executeResource(‘db’) #6 /var/www/library/Zend/Application/Bootstrap/BootstrapAbstract.php(586): Zend_Application_Bootstrap_BootstrapAbstract->_bootstrap(NULL) #7 /var/www/library/Zend/Applicatio in /var/www/library/Zend/Db/Adapter/Pdo/Abstract.php on line 342

这样的错误提示是因为木有pdo扩展,安装即可

声明: 此文观点不代表本站立场;转载须要保留原文链接;版权疑问请联系我们。