Concept
Nginx開發是針對俄羅斯第二大流量的網站 Rambler.ru ,所以目前沒有支援虛擬主機的功能
Installation on Ubuntu
- sudo apt-get install nginx
- /etc/init.d/nginx start
- modify the configuration of default/etc/nginx/sites-available/default
server {
listen
80
default
;
server_name localhost;
access_log /var/log/nginx/localhost.access.log;
## Default location
location / {
root /var/www;
index index.php index.htm index.html;
}
## Images and
static
content is treated different
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
access_log off;
expires 30d;
root /var/www;
}
## Parse all .php file in the /var/www directory
location ~ .php$ {
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_pass backend;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name;
include fastcgi_params;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_intercept_errors on;
fastcgi_ignore_client_abort off;
fastcgi_connect_timeout
60
;
fastcgi_send_timeout
180
;
fastcgi_read_timeout
180
;
fastcgi_buffer_size 128k;
fastcgi_buffers
4
256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
}
## Disable viewing .htaccess & .htpassword
location ~ /\.ht {
deny all;
}
}
upstream backend {
server
127.0
.
0.1
:
9000
;
}
- modify the configuration of nginx
/etc/nginx/nginx.conf
user www-data www-data; worker_processes 4 ; error_log /var/log/nginx/error.log; pid /var/run/nginx.pid; events { worker_connections 1024 ; # multi_accept on; } http { include /etc/nginx/mime.types; default_type application/octet-stream; access_log /var/log/nginx/access.log; sendfile on; #tcp_nopush on; #keepalive_timeout 0 ; keepalive_timeout 65 ; tcp_nodelay on; gzip on; gzip_disable "MSIE [1-6]\.(?!.*SV1)" ; gzip_comp_level 2 ; gzip_proxied any; gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript; include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; } |
- add the source of package
/etc/apt/source.list
... ... deb http: //ppa.launchpad.net/brianmercer/php/ubuntu lucid main deb-src http: //ppa.launchpad.net/brianmercer/php/ubuntu lucid main |
- sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 8D0DC64F
- sudo apt-get update
- sudo apt-get install php5-cgi php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl php5-json php5-suhosin php5-common php-apc php5-dev
- sudo apt-get install php5-fpm php5-cgi
- sudo /etc/init.d/nginx restart
- /etc/init.d/php5-fpm start
Installation on Windows 7
- download the nginx in here
- install it! and we can see the result at C:\nginx
- download the php lib in here
- unzip it to *C:\nginx\php*
- make sure the php-cgi.exe arrival at C:\nginx\php\php-cgi.exe
- add the configuration on nginx.conf
nginx.conf
location ~ .php$ { root html; fastcgi_pass 127.0 . 0.1 : 9000 ; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME c:/nginx/html/$fastcgi_script_name; include fastcgi_params; } |
- modify the batch files
start-nginx.bat
@ECHO OFF c:\nginx\nginx.exe c:\nginx\php\php-cgi.exe -b 127.0 . 0.1 : 9000 -c c:\nginx\php\php.ini ping 127.0 . 0.1 -n 1 >NUL echo Starting nginx echo . echo . echo . ping 127.0 . 0.1 >NUL EXIT |
stop-nginx.bat
@ECHO OFF taskkill /f /IM nginx.exe taskkill /f /IM php-cgi.exe EXIT |
沒有留言:
張貼留言