好久不寫日志了,哪怕是網(wǎng)上摘抄的都很少在此記錄了,自己怎么這么懶了啊。
之前都是用apache服務器來配置php環(huán)境,今天有興趣了解一些nginx來配置php環(huán)境。是在linux下配置。
利用Linux Nginx架設高性能的Web環(huán)境 Linux Nginx ("engine x") 是一個高性能的 HTTP 和反向代理服務器,也是一個 IMAP/POP3/SMTP 代理服務器。 Linux Nginx 是由 Igor Sysoev 為俄羅斯訪問量第二的 Rambler.ru 站點開發(fā)的,它已經(jīng)在該站點運行超過兩年半了。Igor 將源代碼以類BSD許可證的形式發(fā)布。
實驗環(huán)境ubuntu
- # tar -zxvf nginx-0.8.5.tar.gz
- # cd nginx-0.8.5
- # ./configure --prefix=/usr/local/nginx –with-http_stub_status_module –with-http_ssl_module –with-http_gzip_static_module –with-http_ssl_module(安裝路徑及
- 所需依賴包)--prefix(安裝路徑)
- # make && make install
或者用 /usr/local/nginx/sbin/nginx 啟動 nginx
/usr/local/nginx/sbin/nginx -s quit 退出nginx
/usr/local/nginx/sbin/nginx -s reload 重新載入
還需要安裝 apt-get install spawn-fcgi
每次運行的時候執(zhí)行:告訴php需要相應的端口號 跟之前做的java一樣
spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u www-data -g www-data -f
/usr/bin/php-cgi(必須滴)
2、spawn-fcgi,用來啟動PHP的FastCGI模式
(linux下載包用 wget方式 或者可以直接安裝用apt-get install spawn-fcgi方式)
wget http://www.lighttpd.net/download/spawn-fcgi-1.6.3.tar.gz
tar -zxf spawn-fcgi-1.6.3.tar.gz
cd spawn-fcgi-1.6.3
./configure –bindir=/usr/bin –libdir=/usr/lib –prefix=/etc
make&&make install
- # tar -zxvf mysql-5.0.67.tar.gz
- # cd mysql-5.0.67
- # groupadd mysql
- # useradd -g mysql -s /sbin/nologin -M mysql
- # ./configure --prefix=/usr/local/mysql --with-charset=gbk --with-extra-charset=all --enable-hread-safe-client
--enable-local-infile --with-low-memory- # make && make install
- # cp support-files/my-medium.cnf /etc/my.cnf
- # chown -R mysql.mysql /usr/local/mysql/
- # /usr/local/mysql/bin/mysql_install_db --user=mysql
- # chown -R root.root /usr/local/mysql/
- # chown -R mysql.mysql /usr/local/mysql/var/
- # /usr/local/mysql/bin/mysqld_safe --user=mysql &
- #cp support-files/mysql.server /etc/rc.d/init.d/mysqld
- #chmod 755 /etc/rc.d/init.d/mysqld
- #chkconfig --add mysqld
- #chkconfig --level 345 mysqld on添加root密碼
- # /usr/local/mysql/bin/mysqladmin -u root password "123456"
- 測試一下:# /usr/local/mysql/bin/mysql -u root -p輸入密碼:123456,看能不能進入到數(shù)據(jù)庫
- # echo "/usr/local/mysql/lib/mysql">>/etc/ld.so.conf
- # ldconfig
- # ldconfig -v
- 添加/usr/local/mysql/bin到環(huán)境變量PATH中
- #echo "export PATH=$PATH:/usr/local/mysql/bin">>/etc/profile
- #source /etc/profile
- # tar -jxvf php-5.2.6.tar.bz2
- # gzip -cd php-5.2.6-fpm-0.5.9.diff.gz |patch -d php-5.2.6 -p1
- # cd php-5.2.6
- # ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --enable-fastcgi --enable-fpm
- --with-config-file-path=/usr/local/php/etc --enable-force-cgi-redirect
- # make && make install
- # cp php.ini-recommended /usr/local/php/etc/php.ini
- # vi /usr/local/php/php-fpm.conf
- (1)<value name="listen_address">127.0.0.1:9000</value>修改為<value name="listen_address">IP:9000</value>
//本機就用默認的127.0.0.1- (2)下面這兩行去掉注釋并修改
- <value name="sendmail_path">/usr/sbin/sendmail -t -i</value>
- <value name="display_errors">1</value>
- (3)<value name="user">nobody</value> //去注釋
- (4)<value name="group">nobody</value> //去注釋
- (5)<value name="allowed_clients">127.0.0.1</value> //允許連接的PC,本機就用127.0.0.1
- # vim /usr/local/nginx/conf/nginx.conf
- user nobody;
- worker_processes 8;
- pid /usr/local/nginx/logs/nginx.pid;
- worker_rlimit_nofile 1024;
- events
- {use epoll;
- worker_connections 1024;}
- http{
- include mime.types;
- default_type application/octet-stream;
- server_names_hash_bucket_size 128;
- client_header_buffer_size 32k;
- large_client_header_buffers 4 32k;
- client_max_body_size 8m;
- sendfile on;
- tcp_nopush on;
- keepalive_timeout 60;
- tcp_nodelay on;
- fastcgi_connect_timeout 300;
- fastcgi_send_timeout 300;
- fastcgi_read_timeout 300;
- fastcgi_buffer_size 64k;
- fastcgi_buffers 4 64k;
- fastcgi_busy_buffers_size 128k;
- fastcgi_temp_file_write_size 128k;
- gzip on;
- gzip_min_length 1k;
- gzip_buffers 4 16k;
- gzip_http_version 1.0;
- gzip_comp_level 2;
- gzip_types text/plain application/x-javascript text/css application/xml;
- gzip_vary on;
- server {
- listen 80;
- server_name www.bbb.com;
- root /www/uuweb;
- index index.html index.htm index.php;
- location ~ .*\.(php|php5)?$ { 或者 location / {
- 不知道怎么回事我用前一個css不起作用,只能用后面一個。
- root /www/uuweb;
- fastcgi_pass 127.0.0.1:9000;
- fastcgi_index index.php;
- fastcgi_param SCRIPT_FILENAME /www/uuweb$fastcgi_script_name;
- include fastcgi_params;}
- #location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
- #{expires 30d;}
- #location ~ .*\.(js|css)?$
- #{expires 1h;}
- log_format access '$remote_addr - $remote_user [$time_local] "$request" '
- '$status $body_bytes_sent "$http_referer" '
- '"$http_user_agent" $http_x_forwarded_for';
- access_log /var/logs/access.log access;}}