一、到官网下载nginx相应的版本:官网地址:http://www.nginx.org/
下载完成后解压 进入目录:
开始安装编译:(默认安装到usr/local/nginx目录下)
./configure
make
make install
安装完成后可以修改配置 /usr/local/nginx/conf/nginx.conf
启动nginx服务
/usr/local/nginx/sbin/nginx
重启
/usr/local/nginx/sbin/nginx -s reload
nginx.conf 基本配置:
user nobody;
worker_processes 1;
worker_rlimit_nofile 8192;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
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" "$request_body" "$http_HEADER"';
log_format debug '[$time_local] "$request" '
'$body_bytes_sent "$http_HEADER" "$request_body"';
sendfile on;
tcp_nopush on;
keepalive_timeout 3000;
tcp_nodelay on;
gzip on;
gzip_comp_level 5;
gzip_http_version 1.0;
gzip_min_length 1024;
gzip_buffers 4 8k;
gzip_types text/plain application/x-javascript text/css application/xml;
client_header_buffer_size 4k;
large_client_header_buffers 4 16k;
proxy_connect_timeout 60;
proxy_send_timeout 120;
proxy_read_timeout 120;
proxy_buffer_size 64k;
proxy_buffers 64 16k;
proxy_busy_buffers_size 256k;
upstream hhvmfastcgi {
server 127.0.0.1:90 weight=1;
}
}
conf/vhosts 目录下配置站点:
server {
listen 80;
server_name www.xxx.com;
root /www
index index.php index.html;
charset utf-8;
access_log logs/www.xxx.com.log main;
error_page 500 502 503 504 /50x.html;
location / {
if (-f $request_filename) {
break;
}
if ($request_filename ~* "\.(js|ico|gif|jpe?g|bmp|png|css)$") {
break;
}
if (!-e $request_filename) {
rewrite . /index.php last;
}
}
location = /50x.html {
root html;
}
location ~ .+\.(php|do)?$
{
fastcgi_pass hhvmfastcgi;
fastcgi_connect_timeout 600;
fastcgi_send_timeout 1200;
fastcgi_read_timeout 1200;
fastcgi_buffers 64 16k;
fastcgi_buffer_size 64k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ .+\.(dat|sql|tgz|gz|tar|zip)?$
{
deny all;
}
location ~ /\.ht {
deny all;
}
}
同样到官网下载php源码:官网地址:http://www.php.net/
开始安装编译:(默认安装到usr/local/nginx目录下)
./configure --prefix=/usr/local/php --enable-sockets=shared --with-mysql=shared,mysqlnd (指定安装目录,默认安装mysql扩展支持)
make
make install
更详细的配置安装:
./configure --prefix=/usr/local/php --enable-fpm --with-gd --with-curl --with-freetype-dir=/usr/local/freetype --enable-gd-native-ttf --enable-mbstring --enable-calendar --with-gettext --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd
/usr/local/lib/php.ini
扩展安装
在php/ext/目录下有很多的php扩展,需要安装就进入相应的目录然后执行以下命令,生成configure等文件进行编译,编译完成后在php.ini添加扩展支持即可。
/usr/local/bin/phpize
./configure --with-php-config=/usr/local/bin/php-config
php启动
/usr/local/bin/php-fpm