您的位置:首页 > 其它

程序部署(六)

2016-05-03 00:00 155 查看
摘要: 编译nginx-1.9.15

一.编译nginx

1.下载nginx

cd/home/caojiabin/下载

wget http://nginx.org/download/nginx-1.9.15.tar.gz
2.解压

tar -zxvf nginx-1.9.15.tar.gz

3.安装

#注释

–with-http_stub_status_module:支持nginx状态查询

–with-http_ssl_module:支持https

–with-http_spdy_module:支持google的spdy,想了解请百度spdy,这个必须有ssl的支持

–with-pcre:为了支持rewrite重写功能,必须制定pcre

综上所述根据自己的需求而定,要增加的参数,要先安装pcre,要支持https要安装ssl

cd nginx-1.9.15

./configure --prefix=/usr/local/nginx

make test && make install

4.配置

cd /usr/local/nginx

vim conf/nginx.conf

(1.)添加index.php来支持php

location / {

root /var/www;

index index.html index.htm index.php;

}

(2.)对接php-fpm

location ~ \.php$ {

root /var/www;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}

(3.)先引入hosts目录便于管理域名

#vhosts

include /usr/local/nginx/vhosts/*;

保存、退出nginx.conf

(4.)虚拟域名配置和index.php处理

mkdir vhosts

vim dm.test.com.conf

添加如下代码:

server {

listen 80;

server_name dm.test.com;

# access_log /usr/logs/dm.test.com.log;

location / {

#指定项目目录

root /var/www/DataManager/;

index index.php index.html index.htm;

}

#去除index.php

if (-f $request_filename/index.php){

rewrite (.*) $1/index.php;

}

if (!-f $request_filename){

rewrite (.*) /index.php;

}

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root html;

}

location ~ \.php$ {

#指定项目目录

root /var/www/DataManager/;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

proxy_read_timeout 3000;

#超时时间设置单位秒

fastcgi_connect_timeout 3000;

fastcgi_send_timeout 3000;

fastcgi_read_timeout 3000;

}

location ~ /.ht {

deny all;

}

}

5.调试

#看配置文件是否正确

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

#启动

/usr/local/nginx/sbin/nginx

#关闭

/usr/local/nginx/sbin/nginx -s stop

#重启

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

6.添加黄金变量

cd /etc/profile.d

vim nginx.sh

#路径配置并保存

export NGINX_HOME=/usr/local/nginx

export PATH=$NGINX_HOME/sbin:$PATH
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: