検索
ホームページ運用・保守NginxLinux+Nginx+Phpで高性能WEBサーバーを構築する方法

nginx (「エンジン x」) は、高性能の http およびリバース プロキシ サーバー、および imap/pop3/smtp プロキシ サーバーです。 nginx は、ロシアで 2 番目にアクセス数の多いサイトである rambler.ru のために igor sysoev によって開発され、2 年半以上運営されています。 igor は、BSD のようなライセンスに基づいてソース コードをリリースします。 nginx はまだベータ版ですが、その安定性、豊富な機能セット、サンプル構成ファイル、およびシステム リソースの消費量の少なさですでに知られています。

インストール手順

1. php5.2.9

tar zxvf libiconv-1.13.tar.gz## に必要なサポート ライブラリをコンパイルしてインストールします。 # cd libiconv-1.13/
./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
/sbin/ldconfig
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

tar zxvf mcrypt-2.6.8.tar.gz

cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make
make install
cd ../


2. mysql 5.1.34 拡張ライブラリ ## をコンパイルしてインストールします。 ## /usr/sbin/groupadd mysql/usr/sbin/useradd -g mysql mysql

tar zxvf mysql-5.1.34.tar.gz

cd mysql-5.1.34/
。 /configure --prefix=/usr/local/webserver/mysql/ --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables --with-readline -- with-ssl --with-embedded-server --enable-local-infile --with-plugins=innobase
make && make install
chmod w /usr/local/webserver/mysql
chown -r mysql:mysql /usr/local/webserver/mysql
cd ../

mysql のインストールはここでは省略します

3. コンパイルしてインストールします。 php (fastcgi モード)


tar zxvf php-5.2.9.tar.gzgzip -cd php-5.2.9-fpm-0.5.10.diff.gz | patch -d php-5.2 .9 -p1

cd php-5.2.9/

./configure --prefix=/usr/local/webserver/php --with-config-file-path=/usr/local/ webserver/php /etc --with-mysql=/usr/local/webserver/mysql --with-mysqli=/usr/local/webserver/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-discard -path - -enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable- fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash - -enable- pcntl --enable-sockets --with-ldap --with-ldap-sasl
make zend_extra_libs='-liconv'
make install
cp php.ini-dist /usr/local/ webserver/php /etc/php.ini
cd ../


4. php-fpm 設定ファイルを変更します


rm -f / usr/local/webserver/php/etc/php-fpm.confvi /usr/local/webserver/php/etc/php-fpm.conf

次のように入力します。




/usr /local/webserver/php/logs/php-fpm.pid
/usr/local/webserver/php/logs/php-fpm.log> ;
注意値>
10値>
1m
5s
yes



default
127.0.0.1:9000

-1


0666


/usr/sbin/sendmail -t -i
1
gt;
www
www

static
128
gt;
20
5
35


0s
0s
logs/slow.log
51200値>
0値>
値>
値>
はい値>
500
127.0.0.1

$hostname
/usr/local/bin:/usr/bin:/bin
/tmp
/tmp
/tmp
$ostype
$machtype
2



5、创建www用户组およびwww用户

/usr/sbin/groupadd www
/usr/sbin/useradd -g www wwwwww


六、编译インストールnginx

tar zxvf nginx-0.6.35.tar.gz
cd nginx-0.6.35/
默认インストール:
./configure
make && make install
默认情况以下、nginx は /usr/local/nginx にインストールされます。この設定は、セッション選択を設定することで変更できます。

例:
./configure --user= www --group=www --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install
cd ../

# #七、创建fcgi.conf文件

rm -f /usr/local/webserver/nginx/conf/fcgi.conf

vi /usr/local/webserver/nginx/conf/fcgi .conf

次の内容を入力します:

fastcgi_param ゲートウェイ インターフェイス cgi/1.1;
fastcgi_param サーバー_ソフトウェア nginx;

fastcgi_param クエリ文字列 $query_string;
fastcgi_param request_method $request_method;
fastcgi_param content_type $content_type;
fastcgi_param content_length $content_length ;

fastcgi_param スクリプト ファイル名 $document_root$fastcgi_script_name;
fastcgi_param スクリプト名 $fastcgi_script_name;
fastcgi_param request_uri $request_uri;
fastcgi_param document_uri $document_uri;
fastcgi_param document_root $document_root;
fastcgi_paramサーバープロトコル $server_protocol;

fastcgi_param リモートアドレス $remote_addr;
fastcgi_param リモートポート $remote_port;
fastcgi_param サーバーアドレス $server_addr;
fastcgi_param サーバーポート $server_port;
fastcgi_param サーバー名 $server_name;

# php のみ。php が --enable-force-cgi-redirect でビルドされた場合に必要です。
fastcgi_param redirect_status 200;


八、nginx 構成文件

rm -f /usr/local/webserver/nginx/conf/nginx.conf
vi /usr/local/webserver/nginx/conf/nginx.conf

以下の内容に入る:

ユーザー www www;
worker_processes 8;
error_log /usr/local/webserver/nginx/logs/logs/nginx_error.log crit;
pid /usr/local/webserver/ nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;
events {
epoll を使用;
worker_connections 51200;
}

http {
mime.types を含める;
default_type application/octet-stream;
charset utf-8;

server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;

sendfile オン;
tcp_nopush オン;
keepalive_timeout 60;
tcp_nolay on;

fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k ;
fastcgi_buffers 8 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 クローラー $binary_remote_addr 10m;

#多个站点設置,ステーションポイント文件夹はnginxのhtml目录に公開する必要があり、そうでない場合は多ステーションポイント
server {
listen 80;
server_name www.v-ec.com;
root /usr/local/webserver /nginx/html/www.v-ec.com;
indexindex.phpindex.html;

location ~ .*\.(php|php5)?$ {

#fastcgi_pass unix :/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_indexindex.php;
include fcgi.conf;
}

location ~ .* \.(gif|jpg|jpeg|png|bmp|swf)$ {
有効期限は 30 日;
}

location ~ .*\.(js|css)?$ {

有効期限は 6 時間です;
}

log_format veclog '$remote_addr - $remote_user [$time_local] "$request" '

'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent " $http_x_forwarded_for';
access_log logs/vec.log veclog;
}
#多站点設置、站点文件夹必须放在nginx的html目录、否多站点
server {
listen 80;
server_name www.w3cgroup.com;
root /usr/local/webserver/nginx/html/www.w3cgroup.com;
indexindex.phpindex.html;

location ~ .*\.(php|php5)?$ {

#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index インデックス。 php;
include fcgi.conf;
}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
有効期限は 30 日;
}

location ~ .*\.(js|css)?$ {

expires 6h;
}

log_format w3cclog '$remote_addr - $remote_user [$time_local] " $request" '

'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
access_log logs/w3c.log w3clog;
}
}

九、構成开机自動启动nginx php

vi /etc/rc.local

在末尾增以下の内容:

ulimit -shn 51200

/usr/local/webserver/php/sbin/php-fpm start
/usr/local/webserver/nginx/sbin/nginx


十、拡張linux内核パラメータ

vi /etc/sysctl.conf

末尾に以下の内容を追加:

net.ipv4.tcp_fin_timeout = 30

net. ipv4.tcp_keepalive_time = 300
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1

使用配置即生效:

/sbin/sysctl –p

ここに到達すると、linux を再起動できます。予想外のメッセージが表示されます。nginx

平滑重启nginx

ps 補助 | grep nginx

nginx のマスター プロセスに到達します。例: 5800、その後 kill
kill –hup 5800

平滑重启php

/usr/local/webserver/php/sbin /php-fpm restart

php-fpm のその他のコマンド:start |停止 |やめる |再起動 |リロード |ログローテート

以上がLinux+Nginx+Phpで高性能WEBサーバーを構築する方法の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明
この記事は亿速云で複製されています。侵害がある場合は、admin@php.cn までご連絡ください。
nginxを開始する方法nginxを開始する方法Apr 14, 2025 pm 01:06 PM

質問:nginxを開始する方法は?回答:nginxスタートアップnginx検証nginxはnginxを開始しました他のスタートアップオプションを自動的に開始

Nginxが開始されるかどうかを確認する方法Nginxが開始されるかどうかを確認する方法Apr 14, 2025 pm 01:03 PM

nginxが開始されるかどうかを確認する方法:1。コマンドラインを使用します:SystemCTLステータスnginx(Linux/unix)、netstat -ano | FindStr 80(Windows); 2。ポート80が開いているかどうかを確認します。 3.システムログのnginx起動メッセージを確認します。 4. Nagios、Zabbix、Icingaなどのサードパーティツールを使用します。

nginxを閉じる方法nginxを閉じる方法Apr 14, 2025 pm 01:00 PM

NGINXサービスをシャットダウンするには、次の手順に従ってください。インストールタイプを決定します:Red Hat/Centos(SystemCtl Status Nginx)またはDebian/Ubuntu(Service Nginx Status)サービスを停止します:Red Hat/Centos(SystemCtl Stop Nginx)またはDebian/Ubuntu(Service Nginx Stop)無効自動起動(オプション):Debuntos/Centos/Centos/Centos/Centos/Centos (syst

Windowsでnginxを構成する方法Windowsでnginxを構成する方法Apr 14, 2025 pm 12:57 PM

Windowsでnginxを構成する方法は? nginxをインストールし、仮想ホスト構成を作成します。メイン構成ファイルを変更し、仮想ホスト構成を含めます。 nginxを起動またはリロードします。構成をテストし、Webサイトを表示します。 SSLを選択的に有効にし、SSL証明書を構成します。ファイアウォールを選択的に設定して、ポート80および443のトラフィックを許可します。

nginx403エラーを解く方法nginx403エラーを解く方法Apr 14, 2025 pm 12:54 PM

サーバーには、要求されたリソースにアクセスする許可がなく、NGINX 403エラーが発生します。ソリューションには以下が含まれます。ファイル許可を確認します。 .htaccess構成を確認してください。 nginx構成を確認してください。 SELINUXアクセス許可を構成します。ファイアウォールルールを確認してください。ブラウザの問題、サーバーの障害、その他の可能なエラーなど、他の原因をトラブルシューティングします。

Linuxでnginxを開始する方法Linuxでnginxを開始する方法Apr 14, 2025 pm 12:51 PM

Linuxでnginxを開始する手順:nginxがインストールされているかどうかを確認します。 systemctlを使用して、nginxを開始してnginxサービスを開始します。 SystemCTLを使用して、NGINXがシステムスタートアップでNGINXの自動起動を有効にすることができます。 SystemCTLステータスNGINXを使用して、スタートアップが成功していることを確認します。 Webブラウザのhttp:// localhostにアクセスして、デフォルトのウェルカムページを表示します。

Nginxが起動されているかどうかを確認する方法は?Nginxが起動されているかどうかを確認する方法は?Apr 14, 2025 pm 12:48 PM

Linuxでは、次のコマンドを使用して、nginxが起動されるかどうかを確認します。SystemCTLステータスNGINXコマンド出力に基づいて、「アクティブ:アクティブ(実行)」が表示された場合、NGINXが開始されます。 「アクティブ:非アクティブ(dead)」が表示されると、nginxが停止します。

nginx304エラーを解く方法nginx304エラーを解く方法Apr 14, 2025 pm 12:45 PM

質問への回答:304変更されていないエラーは、ブラウザがクライアントリクエストの最新リソースバージョンをキャッシュしたことを示しています。解決策:1。ブラウザのキャッシュをクリアします。 2.ブラウザキャッシュを無効にします。 3.クライアントキャッシュを許可するようにnginxを構成します。 4.ファイル許可を確認します。 5.ファイルハッシュを確認します。 6. CDNまたは逆プロキシキャッシュを無効にします。 7。nginxを再起動します。

See all articles

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

AI Hentai Generator

AI Hentai Generator

AIヘンタイを無料で生成します。

ホットツール

SecLists

SecLists

SecLists は、セキュリティ テスターの究極の相棒です。これは、セキュリティ評価中に頻繁に使用されるさまざまな種類のリストを 1 か所にまとめたものです。 SecLists は、セキュリティ テスターが必要とする可能性のあるすべてのリストを便利に提供することで、セキュリティ テストをより効率的かつ生産的にするのに役立ちます。リストの種類には、ユーザー名、パスワード、URL、ファジング ペイロード、機密データ パターン、Web シェルなどが含まれます。テスターはこのリポジトリを新しいテスト マシンにプルするだけで、必要なあらゆる種類のリストにアクセスできるようになります。

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

強力な PHP 統合開発環境

AtomエディタMac版ダウンロード

AtomエディタMac版ダウンロード

最も人気のあるオープンソースエディター

PhpStorm Mac バージョン

PhpStorm Mac バージョン

最新(2018.2.1)のプロフェッショナル向けPHP統合開発ツール

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)