程序部署(六)
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
一.编译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
相关文章推荐
- python函数基础
- python函数深入
- Unity3d之Mecanim(新版动画系统)
- 如何快速体验微商城?
- EL/JSTL
- python set
- 怎样快速解决EDIUS中文件无法打开问题
- Linux 输入和输出
- ActiveMQ Connectors
- ViewPager + Fragment 取消预加载
- Sublime Text 2 快捷键
- 神奇的504 Bad Gateway Timeout
- 前端开发学习之旅-css篇
- LitePal的使用
- Dialog: sweet-alert-dialog
- android 个推配置
- ShowTipsView
- 【云豹直播系统】专业制作仿映客手机直播app、视频直播系统
- Android HTTPS 10分钟实现自签名SSL证书
- 美猴云与陕西省旅游信息化工程实验室达成战略合作打造“互联网+旅游”