3.4 配置防火墙80端口
#修改防火墙配置:
# vi + /etc/sysconfig/iptables
#添加配置项
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
#重启防火墙
# service iptables restart
3.5 上传配置文件
1)上传nginx.conf (文件下载地址见上面的Linux公社资源站)
# cd /usr/local/nginx/conf
# rz nginx.conf
2) 上传fastcgi_params.phis
# rz fastcgi_params.phis
3.6 启动停止重启与测试
1)启动
#方法1
# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
#方法2
# cd /usr/local/nginx/sbin
# ./nginx
2) 停止
#查询nginx主进程号
ps -ef | grep nginx
#停止进程
kill -QUIT 主进程号
#快速停止
kill -TERM 主进程号
#强制停止
pkill -9 nginx
3) 重启(首次启动需:/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf)
/usr/local/nginx/sbin/nginx -s reload
4)测试
#测试端口
netstat -na | grep 80
#浏览器中测试
:80
3.7 配置Nginx支持php
1)方式一:手动修改
vi /usr/local/nginx/conf/nginx.conf #编辑配置文件
user www www; #首行user去掉注释,修改Nginx运行组为www www;必须与/usr/local/php5/etc/php-fpm.conf中的user,group配置相同,否则php运行出错
index index.php index.html index.htm; #添加index.php
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
#root html;#此处和server下面root保持一致,默认为html
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html/$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
注意:取消FastCGI server部分location的注释,并要注意fastcgi_param行的参数,改为/data/webroot/(此为网站根目录绝对路径)$fastcgi_script_name
/etc/init.d/nginx restart #重启nginx
2)方式二:上传配置文件
如3.5节操作方式,或手动填写配置文件
# vi /usr/local/php5/sbin/php-fpm
<?xml version="1.0" ?>
<configuration>
All relative paths in this config are relative to php's install prefix
<section>
Pid file
<value>/usr/local/php5/logs/php-fpm.pid</value>
Error log file
<value>/data0/logs/php/php-fpm.log</value>
Log level notice alert, error, warn, notice, debug
<value>warn</value>
When this amount of php processes exited with SIGSEGV or SIGBUS ...
<value>10</value>
... in a less than this interval of time, a graceful restart will be initiated.
Useful to work around accidental curruptions in accelerator's shared memory.
<value>1m</value>
Time limit on waiting child's reaction on signals from master
<value>5s</value>
Set to 'no' to debug fpm
<value>yes</value>
</section>
<workers>
<section>
Name of pool. Used in logs and stats.
<value>default</value>
Address to accept fastcgi requests on.
Valid syntax is 'ip.ad.re.ss:port' or just 'port' or '/path/to/unix/socket'
<value>127.0.0.1:9000</value>
<value>
Set listen(2) backlog
<value>1024</value>