您的位置:首页 > 运维架构 > Nginx

简单运行Nginx + PHP

2015-07-09 10:21 567 查看
0. Nginx 安装

zlib<span style="white-space:pre">	</span>
tar -zxvf zlib-1.2.7.tar.gz 
cd zlib-1.2.7 
./configure 
make 
make install 
pcre<span style="white-space:pre">	</span>
tar -zxvf pcre-8.32.tar.gz 
cd pcre-8.32 
./configure 
make 
make install 
 

下载Nignx module:
download from:  https://github.com/openresty/headers-more-nginx-module/archive/v0.26.zip
unzip  headers-more-nginx-module-0.26.zip
cd headers-more-nginx-module-0.26
[irobot@TEST headers-more-nginx-module-0.26]$ pwd 
/u01/soft/headers-more-nginx-module-0.26

安装Nginx:
wget http://nginx.org/download/nginx-1.7.10.tar.gz tar -xzvf nginx-1.7.10.tar.gz 
cd nginx-1.7.10/ 
./configure --prefix=/u01/soft/nginx  --add-module=/u01/soft/headers-more-nginx-module-0.26
make 
make install

1. 安装PHP 5.6:

[irobot@TEST php-5.6.10]$ whereis curl 
curl: /usr/bin/curl /usr/include/curl /usr/share/man/man1/curl.1.gz 
[irobot@TEST php-5.6.10]$ which curl 
/usr/bin/curl

[irobot@TEST php-5.6.10]$ pwd 
/home/irobot/zhoutao/php-5.6.10 
[irobot@TEST php-5.6.10]$

wget http://cn2.php.net/get/php-5.6.10.tar.gz/from/this/mirror tar xzvf php-5.6.10.tar.gz
cd php-5.6.10
./configure --enable-fastcgi --enable-debug --with-curl=/usr/bin/curl
make
make install

------------------------
[root@TEST php-5.6.10]# make install 
Installing shared extensions: /usr/local/lib/php/extensions/debug-non-zts-20131226/ 
Installing PHP CLI binary: /usr/local/bin/ 
Installing PHP CLI man page: /usr/local/php/man/man1/ 
Installing PHP CGI binary: /usr/local/bin/ 
Installing PHP CGI man page: /usr/local/php/man/man1/ 
Installing build environment: /usr/local/lib/php/build/ 
Installing header files: /usr/local/include/php/ 
Installing helper programs: /usr/local/bin/ 
program: phpize 
program: php-config 
Installing man pages: /usr/local/php/man/man1/ 
page: phpize.1 
page: php-config.1 
Installing PEAR environment: /usr/local/lib/php/ 
[PEAR] Archive_Tar - already installed: 1.3.12 
[PEAR] Console_Getopt - already installed: 1.3.1 
[PEAR] Structures_Graph- already installed: 1.0.4 
[PEAR] XML_Util - already installed: 1.2.3 
[PEAR] PEAR - already installed: 1.9.5 
Wrote PEAR system config file at: /usr/local/etc/pear.conf 
You may want to add: /usr/local/lib/php to your php.ini include_path 
/home/irobot/php-5.6.10/build/shtool install -c ext/phar/phar.phar /usr/local/bin 
ln -s -f phar.phar /usr/local/bin/phar 
Installing PDO headers: /usr/local/include/php/ext/pdo/
------------------------

[root@TEST php-5.6.10]# cp php.ini-production /usr/local/lib/php.ini
                        >>> 将 /usr/local/lib/php.ini 设置为: output_buffering = on    
                        >>> 以上配置打开后,会影响性能。最好看看PHP程序是否能够不使用这样的配置!!!
                        >>> 参考链接: http://zhanglulu33.blog.163.com/blog/static/112799542010112810497281/  
                        >>>将 /usr/local/lib/php.ini 设置为: default_mimetype = ""
                        >>>PHP默认是:  default_mimetype = "text/html"
                        >>>规避Nginx+PHP组合下,对于css文件的content-type总是返回text/html。 正常应该返回是text/css。
                        >>> 参考链接: http://www.nqhua.com/2011/08/01/208.html 
启动 php-cgi:

nohup php-cgi -b 13344 -c /usr/local/lib/php.ini  >>  /home/irobot/php.log 2>&1 &

2. 存放HTML5
/u01/soft/htm5root   

3. 设置Nignx  

[irobot@TEST conf]$ cat nginx.conf 
worker_processes 8; 
worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000; 

events { 
use epoll; 
worker_connections 65536; 
} 

http { 
default_type application/octet-stream; 
#include mime.types; 
include /u01/soft/nginx_new/conf/mime.types; 

charset utf-8; 

client_header_buffer_size 32k; 
large_client_header_buffers 4 32k; 

sendfile on; 
tcp_nodelay on; 

keepalive_timeout 180; 

tcp_nopush on; 
server_names_hash_bucket_size 128; 
client_max_body_size 8m; 

fastcgi_connect_timeout 600; 
fastcgi_send_timeout 600; 
fastcgi_read_timeout 600; 
fastcgi_buffer_size 256k; 
fastcgi_buffers 16 256k; 
fastcgi_busy_buffers_size 512k; 
fastcgi_temp_file_write_size 512k; 

gzip on; 
gzip_min_length 1k; 
gzip_buffers 4 16k; 
#gzip_proxied any; 
gzip_http_version 1.1; 
gzip_disable "MSIE [1-6]\."; 
gzip_comp_level 2; 
gzip_types text/plain application/x-javascript text/css application/xml; 
gzip_vary on; 

upstream web_server { 

server 192.168.1.100:8080 weight=1 max_fails=2 fail_timeout=10s; 

} 

server { 
listen 33765; 
server_name 192.168.1.1; 

location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$ 
{ 
if ($request_uri ~* ^/htm5root/) { 
root /u01/soft/; 
expires 1d; 
break; 
} 

root /u01/img/; 
expires 1d; 
} 

location /htm5root/ 
{ 
root /u01/soft/; 

# 这部分是针对PHP的html5 css显示问题。 应该html5问题定位后,不用设置。
if ($request_uri ~ \.css) { 
more_clear_headers 'Content-Type'; 
more_set_headers 'Content-Type: text/css'; 
#more_set_headers -t 'text/css' 'Content-Type: text/css'; 
} 

fastcgi_split_path_info ^(.+\.php)(/.+)$; 
fastcgi_pass 127.0.0.1:13344; 
fastcgi_index index.php; 
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
include fastcgi_params; 
} 

location / { 
proxy_pass http://web_server/;  proxy_redirect off; 
} 

error_page 500 502 503 504 /50x.html; 
location = /50x.html { 
root html; 
} 

} 

} 
[irobot@TEST conf]$ 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: