centos下LNMP構築
LNMPのインストールと構成
1.php関数のrpmパッケージを準備する
2.lnmpの他のソースパッケージを準備する
3.php-5.2を取り付ける.14ソースパッケージに必要な関数サポートパッケージ
export LD_LIBRARY_PATH=/usr/local/lib: LD_LIBRARY_PATH
4.コンパイルインストールMySQL 5.5.3-m3
configureが完了したらVIでMakefileを開きdo_を削除abi_check:ターゲット後のすべての文
5.PHPコンパイルインストール(FastCGIモード)
6.PHP 5拡張モジュールのコンパイルインストールの準備
7.phpを修正する.iniファイルphpモジュールを有効にする
8.php.iniでeAccelerator加速PHPを配置する
9.php-cgiとnginxプロセス実行者ユーザーの準備
Useradd nginx
10.php-fpmプロファイル-php-fpmを作成する.conf
11.php-cgi(fastcgi)プロセスを開始し、127.0を傍受する.0.1の9000ポート、プロセス数128(サーバメモリが3 GB未満の場合、64プロセスのみオープン可能)、ユーザーはnginx:
12.Nginxのインストールに必要なpcreライブラリ
13.Nginxのインストール
14.Nginxプロファイルの変更
15./usr/local/nginx/conf/ディレクトリにfastcgi_を作成するparamsファイル
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fastcgi_を推奨paramはnginxに書いた.confではfastcgiに書くのではなくparamsプロファイルでは、後でデフォルトのphp設定やalias php設定では、phpページのシステムアドレスが異なるなど、構成が柔軟ではありません.
デフォルトphpファイル->/usr/local/nginx/html/index.php
Alias phpファイル->/mnt/bbs/index.php
この時fastcgiを見つけますparamsのSCRIPT_FILENAMEの値は同じであり、alias phpのページが出ないnginxに構成される.confにはそれぞれのphpシステムアドレスが配置する、これは比較的柔軟である.
各接続phpの構成にこの文を追加するのは少し冗長だと思ったらfastcgiに追加します.paramsファイルでは、他のすべてのnginxを1回追加するだけです.confのfastcgiの接続に関するブロックはfastcgiを追加しないでください.param SCRIPT_FILENAME $document_root$fastcgi_script_nameという言葉です.
16.起動nginx,php-fpm,ulimitの構成
17.nginxプロファイル文エラーの確認
/usr/local/nginx/sbin/nginx -t
18.nginxプロセスをスムーズに再起動する
1)Pkill -HUP nginx
2)kill -HUP `pgrep -uroot nginx`
3)/usr/local/nginx/sbin/nginx -s reload
19.毎日定時的にNginxログをカットするスクリプトを作成する
1、スクリプトの作成/usr/local/nginx/sbin/cut_nginx_log.sh
2、crontabを設定し、毎日午前00:00にnginxアクセスログを切断する
crontab -e
00 00 * * */bin/bash/usr/local/nginx/sbin/cut_nginx_log.sh
20.nginx仮想ホストの構成
Vi/usr/local/nginx/conf/nginx.conf
21.リストページ表示
location/{
Autoindex on;#リストページを開く
root html;
index index.html index.php index.htm;
}
22.仮想ディレクトリの設定
location/bbs{
alias/mnt/bbs/;
}
このようにhtml静的ファイルを構成することはできますが、phpダイナミックページは出ません.ブラウザのページに「No input file specified.」と表示されます.のエラーは、実はphpシステムファイルアドレス(SCRIPT_FILENAME)が見つかりません.つまりfastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;の$document_root$fastcgi_script_nameは本物の/mnt/bbs/indexではありません.phpのアドレス、これはどのように解決しますか:
location/bbs {
alias/mnt/bbs/;
index bbs.php index.html index.php;
}
location ~ ^/bbs/{
root/mnt/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
log_format bbs '$document_root$fastcgi_script_name ';
access_log logs/bbs.access.log bbs;
}
#後の2行はログについてです.nginxからfastcgiにコミットされたphpのシステムアドレスSCRIPT_をよりよく観察するためです.FILENAME、ここで$request_を使いますfilenameはSCRIPTにFILENAMEは値を割り当て、ログの結果は/mnt/bbs/indexである.php、ここで私が見つけた問題は$request_です.filenameのrootを/mntに設定しないと$request_filenameの値は:/mnt/bbs/bbs/index.php.
以上より、デフォルトphp設定についてもSCRIPT_についても同様に設定できると結論した.FILENAME:
location ~\.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
log_format php '$document_root$fastcgi_script_name ';
access_log logs/php.access.log php;
}
#ログから$request_が表示されます.filenameの値は/usr/local/nginx/html/indexである.php、以前はデフォルトの/scripts$fastcgi_script_nameは明らかに間違ったphpシステムアドレスであり、ログには/scriipts/indexと表示される.php
23.nginx状態監視
location/nginxstatus{
stub_status on;
access_log off;
}
#クライアントアクセスURL:http://www.test.com/nginxstatus
Active connections–アクティブな接続数
server accepts handled requests-合計111個の接続が処理され、110回の握手が正常に作成され、合計110個のリクエストが処理されました
reading-クライアントの接続数を読み込む.
writing-クライアントに応答するデータの数
waiting-keep-aliveがオンの場合、この値はactive-(reading+writing)に等しく、Nginxが次の要求命令を待っている駐在接続を処理したことを意味する.
24.rewrite正規フィルタリング
location ~\.php$ {
proxy_pass http://127.0.0.1;
}
Rewrite命令の最後のパラメータはflagタグで、サポートされているflagタグは以下の通りです.
Last表示完了rewriteルール
Breakは次のルールに一致しなくなりました
Redirect 302一時リダイレクト
Permanent 301永続リダイレクト
Lastとbreakはuri書き換えを実現するために使用され、ブラウザのアドレスバーのurlアドレスは変わらないが、サーバアクセスの経路が変化し、redirectとpermanentはurlジャンプを実現するために使用され、ブラウザのアドレスバーにはジャンプ後のurlアドレスが表示され、aliasコマンドを使用する場合はlastタグを使用し、proxy_を使用する必要があるpassコマンドの場合はbreakタグを使用し、lastタグは本条rewriteルールの実行が完了すると、その存在するserver{}タグに対して要求を再開し、breakタグは本条ルールのマッチングが完了すると、マッチングを終了し、後のルールに一致しない.
一致する過程でnginxはまず文字列に一致してから正規表現に一致し、最初の正規表現に一致すると検索を停止し、正規表現に一致すると正規表現の検索結果を使用し、正規表現に一致しない場合は文字列の検索結果を使用する.
接頭辞「^~」を用いる文字列へのマッチングを禁止した後、正規表現をチェックしurlにマッチングするとクエリーが停止する.
接頭辞"="を使用する正確なurlマッチングを行うことができ、一致するuriが見つかった場合、「location=/」などのクエリーを停止し、「/」にしかマッチングできず、「/test.html」はマッチングできない.
正規表現のマッチングは、プロファイル内の順序で行い、前の優先順位で書く.
Location =/{
#一致のみ/
[configuration A]
}
Location/{
#は/で始まるクエリと一致するが、正規表現および長い文字列(/bbs/)が優先的に一致する.
[configuration B]
}
Location ^~/images/{
#は、/images/で始まる文字列と一致し、検索を停止するので、正規表現はチェックされません.
[configuration C]
}
Location ~*\.(gif|jpg|jpeg)$ {
#は.gif、.jpg、.jpegで終わるリクエストと一致しますが、/images/内のリクエストはconfiguration cの構成を使用します.
[configuratoin D]
}
要求処理照合結果の例:
/-> configuration A;
/documents/document.html -> configuration B;
/images/1.gif -> configuration c;
/documents/1.jpg -> configuration D;
26.モジュール設定
PHP-version > 5.3.3:
./义齿
または、
masterプロセスは、次の信号を理解することができる.
INT,TERM直ちにQUIT平滑終了USR 1ログファイルを再開USR 2すべてのworkerプロセスを平滑に再ロードし構成とバイナリモジュールを再ロードする
php-fpmオフ:
kill -INT `cat/usr/local/php/var/run/php-fpm.pid`
php-fpm再起動:
kill -USR2 `cat/usr/local/php/var/run/php-fpm.pid`
php-fpmプロセスの数を表示します.
ps aux | grep -c php-fpm
コマンドラインの下でphpを実行し、コマンドが見つからないことを示す
-bash:/usr/bin/php: No such file or directory
vi/etc/profile
ファイルの下部に1行の構成を追加
export PATH=/usr/local/php/bin:$PATH
source/etc/profile
1.php関数のrpmパッケージを準備する
yum groupinstall "Development tools"
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
2.lnmpの他のソースパッケージを準備する
wget http://blog.s135.com/soft/linux/nginx_php/nginx/nginx-0.8.46.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/php/php-5.2.14.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/phpfpm/php-5.2.14-fpm-0.5.14.diff.gz
wget http://blog.s135.com/soft/linux/nginx_php/mysql/mysql-5.5.3-m3.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/libiconv/libiconv-1.13.1.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/mcrypt/libmcrypt-2.5.8.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/mcrypt/mcrypt-2.6.8.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/memcache/memcache-2.2.5.tgz
wget http://blog.s135.com/soft/linux/nginx_php/mhash/mhash-0.9.9.9.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/pcre/pcre-8.10.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/eaccelerator/eaccelerator-0.9.6.1.tar.bz2
wget http://blog.s135.com/soft/linux/nginx_php/pdo/PDO_MYSQL-1.0.2.tgz
wget http://blog.s135.com/soft/linux/nginx_php/imagick/ImageMagick.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/imagick/imagick-2.3.0.tgz
3.php-5.2を取り付ける.14ソースパッケージに必要な関数サポートパッケージ
tar zxvf libiconv-1.13.1.tar.gz;
cd libiconv-1.13.1/;
./configure --prefix=/usr/local;
make && make install;
cd ../;
tar zxvf libmcrypt-2.5.8.tar.gz;
cd libmcrypt-2.5.8/;
./configure;
make && make install;
cd libltdl/;
./configure --enable-ltdl-install;
make && make install;
cd ../../;
tar zxvf mhash-0.9.9.9.tar.gz;
cd mhash-0.9.9.9/;
./configure;
make && make install;
cd ../;
ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la;
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so;
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4;
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8;
ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a;
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la;
ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so;
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2;
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1;
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config;
tar zxvf mcrypt-2.6.8.tar.gz;
cd mcrypt-2.6.8/;
./configure;
make && make install;
cd ../;
configure: error: *** libmcrypt was not found export LD_LIBRARY_PATH=/usr/local/lib: LD_LIBRARY_PATH
4.コンパイルインストールMySQL 5.5.3-m3
./configure --prefix=/usr/local/mysql --without-debug --enable-thread-safe-client --with-pthread --enable-assembler --enable-profiling --with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static --with-extra-charsets=all --with-plugins=all --with-mysqld-user=mysql --without-embedded-server --with-server-suffix=-community --with-unix-socket-path=/tmp/mysql.sock
make && make install
Useradd mysql
# mysql
Setfacl -m u:mysql:rwx -R /usr/local/mysql
Setfacl -m d:u:mysql:rwx -R /usr/local/mysql
#
/usr/local/mysql/bin/mysql_install_db --user=mysql
# mysql test
/usr/local/mysql/bin/mysqld_safe --user=mysql &
# mysql
/usr/local/mysql/bin/mysqladmin -uroot password "123"
# mysql 123
/usr/local/mysql/bin/mysql -uroot -p123
# mysql
cp /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf
# mysql
Vi /etc/my.cnf
default-character-set=utf8
#
character-set-server=utf8
#
collation-server=utf8
#
pkill mysqld
/usr/local/mysql/bin/mysqld_safe --user=mysql &
# mysql
make[2]:***[do_abi_check]エラー1configureが完了したらVIでMakefileを開きdo_を削除abi_check:ターゲット後のすべての文
5.PHPコンパイルインストール(FastCGIモード)
tar zxvf php-5.2.14.tar.gz
gzip -cd php-5.2.14-fpm-0.5.14.diff.gz | patch -d php-5.2.14 -p1
# , php fpm php-cgi
cd php-5.2.14/
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --enable-embed --enable-maintainer-zts --enable-debug --enable-opcache
make ZEND_EXTRA_LIBS='-liconv'
make install
cp php.ini-dist
/usr/local/php/etc/php.ini
cd ../
6.PHP 5拡張モジュールのコンパイルインストールの準備
tar zxvf memcache-2.2.5.tgz
cd memcache-2.2.5/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
cd ../
tar jxvf eaccelerator-0.9.6.1.tar.bz2
cd eaccelerator-0.9.6.1/
/usr/local/php/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config
make && make install
cd ../
tar zxvf PDO_MYSQL-1.0.2.tgz
cd PDO_MYSQL-1.0.2/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql
make && make install
cd ../
tar zxvf ImageMagick.tar.gz
cd ImageMagick-6.5.1-2/
./configure
make && make install
cd ../
tar zxvf imagick-2.3.0.tgz
cd imagick-2.3.0/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
cd ../
7.phpを修正する.iniファイルphpモジュールを有効にする
cp /lnmp/php-5.2.14/php.ini-dist /usr/local/php/etc/php.ini
vi php.ini
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"
extension = "memcache.so"
extension = "pdo_mysql.so"
extension = "imagick.so"
output_buffering = Off output_buffering = On
; cgi.fix_pathinfo=0 cgi.fix_pathinfo=0, Nginx
8.php.iniでeAccelerator加速PHPを配置する
mkdir -p /usr/local/eaccelerator_cache
# eaccelerator
Vi php.ini
[eaccelerator]
zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
eaccelerator.shm_size="64"
eaccelerator.cache_dir="/usr/local/eaccelerator_cache"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="3600"
eaccelerator.shm_prune_period="3600"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
9.php-cgiとnginxプロセス実行者ユーザーの準備
Useradd nginx
10.php-fpmプロファイル-php-fpmを作成する.conf
vi /usr/local/php/etc/php-fpm.conf
0
#0 1,
Unix user of processes
nginx
Unix group of processes
nginx
128
# 128, 2G, 64
65535
# Set open file desc rlimit, ,linux 1024, linux ,ulimit -SHn 65535, , /etc/profile , ,ulimit -a open files 65535
1024
# , How much requests each process should execute before respawn. 1042
11.php-cgi(fastcgi)プロセスを開始し、127.0を傍受する.0.1の9000ポート、プロセス数128(サーバメモリが3 GB未満の場合、64プロセスのみオープン可能)、ユーザーはnginx:
/usr/local/php/sbin/php-fpm start
# php-cgi
/usr/local/php/sbin/php-fpm reload
#
/usr/local/php/sbin/php-fpm stop
# php-fpm, nginx php
12.Nginxのインストールに必要なpcreライブラリ
tar zxvf pcre-8.10.tar.gz
cd pcre-8.10/
./configure
make && make install
cd ../
13.Nginxのインストール
tar zxvf nginx-0.8.46.tar.gz
cd nginx-0.8.46/
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install
cd ../
14.Nginxプロファイルの変更
vi /usr/local/nginx/conf/nginx.conf
user nginx nginx;
worker_processes 8;
# cpu
error_log logs/nginx_error.log
pid /usr/local/nginx/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
events {
use epoll;
worker_connections 65535;
}
http {
include mime.types;
default_type application/octet-stream;
#charset gb2312;
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 65;
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;
#limit_zone crawler $binary_remote_addr 10m;
server {
listen 80;
server_name test.com;
index index.html index.htm index.php;
root /www;
#limit_conn crawler 20;
location ~ .*\.(php|php5)?$ {
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$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 /data1/logs/access.log access;
}
}
15./usr/local/nginx/conf/ディレクトリにfastcgi_を作成するparamsファイル
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fastcgi_を推奨paramはnginxに書いた.confではfastcgiに書くのではなくparamsプロファイルでは、後でデフォルトのphp設定やalias php設定では、phpページのシステムアドレスが異なるなど、構成が柔軟ではありません.
デフォルトphpファイル->/usr/local/nginx/html/index.php
Alias phpファイル->/mnt/bbs/index.php
この時fastcgiを見つけますparamsのSCRIPT_FILENAMEの値は同じであり、alias phpのページが出ないnginxに構成される.confにはそれぞれのphpシステムアドレスが配置する、これは比較的柔軟である.
各接続phpの構成にこの文を追加するのは少し冗長だと思ったらfastcgiに追加します.paramsファイルでは、他のすべてのnginxを1回追加するだけです.confのfastcgiの接続に関するブロックはfastcgiを追加しないでください.param SCRIPT_FILENAME $document_root$fastcgi_script_nameという言葉です.
16.起動nginx,php-fpm,ulimitの構成
1)nginx
Vi /etc/rc.local
/usr/local/nginx/sbin/nginx
2)php-fpm
Vi /etc/rc.local
/usr/local/php/sbin/php-fpm start
3)ulimit
Vi /etc/profile
Ulimit -SHn 65535
17.nginxプロファイル文エラーの確認
/usr/local/nginx/sbin/nginx -t
18.nginxプロセスをスムーズに再起動する
1)Pkill -HUP nginx
2)kill -HUP `pgrep -uroot nginx`
3)/usr/local/nginx/sbin/nginx -s reload
19.毎日定時的にNginxログをカットするスクリプトを作成する
1、スクリプトの作成/usr/local/nginx/sbin/cut_nginx_log.sh
vi /usr/local/nginx/sbin/cut_nginx_log.sh
#!/bin/bash # This script run at 00:00
# The Nginx logs path
logs_path="/usr/local/nginx/logs/"
mkdir -p ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/
mv ${logs_path}access.log ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/access_$(date -d "yesterday" +"%Y%m%d").log
kill -USR1 `cat /usr/local/nginx/nginx.pid`
2、crontabを設定し、毎日午前00:00にnginxアクセスログを切断する
crontab -e
00 00 * * */bin/bash/usr/local/nginx/sbin/cut_nginx_log.sh
20.nginx仮想ホストの構成
Vi/usr/local/nginx/conf/nginx.conf
server {
listen 80;
server_name www.test.com;
index index.html index.php index.htm;
root /web/baidu;
location ~ .*\.(php|php5)?$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
expires 30d;
}
# 30days
location ~ .*\.(js|css)?$ {
expires 1h;
}
# js css 1hour
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 logs/access.log access;
#
}
21.リストページ表示
location/{
Autoindex on;#リストページを開く
root html;
index index.html index.php index.htm;
}
22.仮想ディレクトリの設定
location/bbs{
alias/mnt/bbs/;
}
このようにhtml静的ファイルを構成することはできますが、phpダイナミックページは出ません.ブラウザのページに「No input file specified.」と表示されます.のエラーは、実はphpシステムファイルアドレス(SCRIPT_FILENAME)が見つかりません.つまりfastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;の$document_root$fastcgi_script_nameは本物の/mnt/bbs/indexではありません.phpのアドレス、これはどのように解決しますか:
location/bbs {
alias/mnt/bbs/;
index bbs.php index.html index.php;
}
location ~ ^/bbs/{
root/mnt/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
log_format bbs '$document_root$fastcgi_script_name ';
access_log logs/bbs.access.log bbs;
}
#後の2行はログについてです.nginxからfastcgiにコミットされたphpのシステムアドレスSCRIPT_をよりよく観察するためです.FILENAME、ここで$request_を使いますfilenameはSCRIPTにFILENAMEは値を割り当て、ログの結果は/mnt/bbs/indexである.php、ここで私が見つけた問題は$request_です.filenameのrootを/mntに設定しないと$request_filenameの値は:/mnt/bbs/bbs/index.php.
以上より、デフォルトphp設定についてもSCRIPT_についても同様に設定できると結論した.FILENAME:
location ~\.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
log_format php '$document_root$fastcgi_script_name ';
access_log logs/php.access.log php;
}
#ログから$request_が表示されます.filenameの値は/usr/local/nginx/html/indexである.php、以前はデフォルトの/scripts$fastcgi_script_nameは明らかに間違ったphpシステムアドレスであり、ログには/scriipts/indexと表示される.php
23.nginx状態監視
location/nginxstatus{
stub_status on;
access_log off;
}
#クライアントアクセスURL:http://www.test.com/nginxstatus
Active connections–アクティブな接続数
server accepts handled requests-合計111個の接続が処理され、110回の握手が正常に作成され、合計110個のリクエストが処理されました
reading-クライアントの接続数を読み込む.
writing-クライアントに応答するデータの数
waiting-keep-aliveがオンの場合、この値はactive-(reading+writing)に等しく、Nginxが次の要求命令を待っている駐在接続を処理したことを意味する.
24.rewrite正規フィルタリング
location ~\.php$ {
proxy_pass http://127.0.0.1;
}
Rewrite命令の最後のパラメータはflagタグで、サポートされているflagタグは以下の通りです.
Last表示完了rewriteルール
Breakは次のルールに一致しなくなりました
Redirect 302一時リダイレクト
Permanent 301永続リダイレクト
Lastとbreakはuri書き換えを実現するために使用され、ブラウザのアドレスバーのurlアドレスは変わらないが、サーバアクセスの経路が変化し、redirectとpermanentはurlジャンプを実現するために使用され、ブラウザのアドレスバーにはジャンプ後のurlアドレスが表示され、aliasコマンドを使用する場合はlastタグを使用し、proxy_を使用する必要があるpassコマンドの場合はbreakタグを使用し、lastタグは本条rewriteルールの実行が完了すると、その存在するserver{}タグに対して要求を再開し、breakタグは本条ルールのマッチングが完了すると、マッチングを終了し、後のルールに一致しない.
一致する過程でnginxはまず文字列に一致してから正規表現に一致し、最初の正規表現に一致すると検索を停止し、正規表現に一致すると正規表現の検索結果を使用し、正規表現に一致しない場合は文字列の検索結果を使用する.
接頭辞「^~」を用いる文字列へのマッチングを禁止した後、正規表現をチェックしurlにマッチングするとクエリーが停止する.
接頭辞"="を使用する正確なurlマッチングを行うことができ、一致するuriが見つかった場合、「location=/」などのクエリーを停止し、「/」にしかマッチングできず、「/test.html」はマッチングできない.
正規表現のマッチングは、プロファイル内の順序で行い、前の優先順位で書く.
Location =/{
#一致のみ/
[configuration A]
}
Location/{
#は/で始まるクエリと一致するが、正規表現および長い文字列(/bbs/)が優先的に一致する.
[configuration B]
}
Location ^~/images/{
#は、/images/で始まる文字列と一致し、検索を停止するので、正規表現はチェックされません.
[configuration C]
}
Location ~*\.(gif|jpg|jpeg)$ {
#は.gif、.jpg、.jpegで終わるリクエストと一致しますが、/images/内のリクエストはconfiguration cの構成を使用します.
[configuratoin D]
}
要求処理照合結果の例:
/-> configuration A;
/documents/document.html -> configuration B;
/images/1.gif -> configuration c;
/documents/1.jpg -> configuration D;
26.モジュール設定
Error_log
#
Include
# ,0.6 nginx.conf
Pid
# id
User
#nginx nginx nginx
Worker_processes
# cpu ,4 cpu 4
Worker_rlimit_nofile 65535
# , ulimit -SHn 65535, linux
Worker_connectiones 65535
# 65535
Alias
#
Error_page
#404,500
Index
#index index.html,
Keepalive_timeout
# tcp
Limit_rate
#limit _rate 100k, 100KB/s
Limit_rate_after
#limit_rate_after 1m, 1m, limit_rate
Listen
#listen 192.168.100.1:80, ip
Location
# uri , 、
Resolver
#resolver 8.8.8.8, nginx dns
Root
#
Send_timeout
# tcp , established , , ,nginx , ddos
Sendfile
# sendfile() , , , read write
Server
# web
Server_name
# header host , ip
Tcp_nodelay
# tcp/ip , , keepalive
Tcp_nopush
# sendfile , nginx linux , httpd
Allow
#allow 192.168.100.254, 192.168.100.254
Deny
#deny all,
Autoindex
#autoindex on,
Charset
#charset utf8;source_charset gbk, gbk utf8
Fastcgi_pass
#fastcgi_pass 127.0.0.1:9000;
#fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
#include fastcgi_params;
#fastcgi_pass php-cgi ip
Access_log
#
Proxy_pass
# proxy_pass http://myweb1, nginx upstream
Proxy_set_header
# proxy_set_header Host $host, $host nginx
Proxy_temp_path
# , client_body_temp_path
Stub_status
# stub_status on,
Image_filter
#
PHP-version > 5.3.3:
./义齿
--enable-fpm
PHP-FPMを使用してPHP-CGIのFastCGIプロセスを制御する/usr/local/php/sbin/php-fpm{start|stop|quit|restart|reload|logrotate}
--start php fastcgi
--stop php fastcgi
--quit php fastcgi
--restart php fastcgi
--reload php php.ini
--logrotate log
または、
masterプロセスは、次の信号を理解することができる.
INT,TERM直ちにQUIT平滑終了USR 1ログファイルを再開USR 2すべてのworkerプロセスを平滑に再ロードし構成とバイナリモジュールを再ロードする
php-fpmオフ:
kill -INT `cat/usr/local/php/var/run/php-fpm.pid`
php-fpm再起動:
kill -USR2 `cat/usr/local/php/var/run/php-fpm.pid`
php-fpmプロセスの数を表示します.
ps aux | grep -c php-fpm
コマンドラインの下でphpを実行し、コマンドが見つからないことを示す
-bash:/usr/bin/php: No such file or directory
vi/etc/profile
ファイルの下部に1行の構成を追加
export PATH=/usr/local/php/bin:$PATH
source/etc/profile