検索
ホームページバックエンド開発PHPチュートリアルNginx を使用して PHP サーバーを構築する

通常、PHP 解析サーバーとして Apache を使用します。今回は、強力なリバース プロキシ サーバーである Nginx を使用して PHP サーバーを構築します。 Linux ディストリビューション Ubuntu を例として、Nginx PHP サーバーを構築してみましょう。

まず、Nginx
<code>sudo apt-get install nginx
</code>
をダウンロードしてインストールしますインストールが完了したら、Nginx
<code>sudo /etc/init.d/nginx start
</code>
を起動しますこの時点で、ブラウザを開いてhttp://localhost/と入力すると、nginxサーバーへようこそが表示されます。は正常にインストールされました次に、PHP5をインストールします
<code>sudo apt-get install php5-fpm
</code>
インストールが成功したら、ブラウザーによって要求されたphpファイルがphp cgiによって解析できるように、Nginxの仮想マシン構成を変更する必要があります。 Nginx 仮想マシン構成ファイル /etc/nginx/sites-available/default
<code>sudo vim /etc/nginx/sites-available/default
</code>
を編集し、内部の構成を次の構成内容に変更します:
<code># You may add here your
# server {
#   ...
# }
# statements for each of your virtual hosts to this file

##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

server {
    listen   80; ## listen for ipv4; this line is default and implied
    #listen   [::]:80 default ipv6only=on; ## listen for ipv6

    root /usr/share/nginx/www;
    index index.html index.htm index.php;

    # Make site accessible from http://localhost/
    server_name localhost;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to index.html
        try_files $uri $uri/ /index.html;
        # Uncomment to enable naxsi on this location
        # include /etc/nginx/naxsi.rules
    }

    location /doc/ {
        alias /usr/share/doc/;
        autoindex on;
        allow 127.0.0.1;
        deny all;
    }

    # Only for nginx-naxsi : process denied requests
    #location /RequestDenied {
        # For example, return an error code
        #return 418;
    #}

    error_page 404 /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/www;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

        # With php5-cgi alone:
        fastcgi_pass 127.0.0.1:9000;
        # With php5-fpm:
        #fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
        deny all;
    }
}

# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
#   listen 8000;
#   listen somename:8080;
#   server_name somename alias another.alias;
#   root html;
#   index index.html index.htm;
#
#   location / {
#       try_files $uri $uri/ /index.html;
#   }
#}

# HTTPS server
#
#server {
#   listen 443;
#   server_name localhost;
#
#   root html;
#   index index.html index.htm;
#
#   ssl on;
#   ssl_certificate cert.pem;
#   ssl_certificate_key cert.key;
#
#   ssl_session_timeout 5m;
#
#   ssl_protocols SSLv3 TLSv1;
#   ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP;
#   ssl_prefer_server_ciphers on;
#
#   location / {
#       try_files $uri $uri/ /index.html;
#   }
#}
</code>
変更したばかりの Nginx 構成をリロードします
<code>sudo /etc/init.d/nginx reload
</code>
次に、/ に進みます。 usr/ share/nginx/www/ ディレクトリに新しい phpinfo.php ファイルを作成して、PHP の構成と環境情報を表示します
<code>sudo vim /usr/share/nginx/www/phpinfo.php
</code>
phpinfo.php に次の内容を入力します:
<code><?php phpinfo();
?>
</code>
http://localhost/ と入力しますブラウザで phpinfo.php バージョンやその他の情報を含む PHP 情報ページを表示できます。 PHP5 には、必要に応じてインストールすることもできます。通常、これらのモジュールは php5-mysql などで始まります。Ubuntu にインストールするには、
<code>sudo apt-get install php5-mysql
</code>
PHP5 を再起動することを忘れないでください。 PHPモジュールをインストールしたら、次のコマンドを実行して再起動します 上記では、PHP サーバーを構築するための Nginx の使用法を、関連する内容も含めて紹介しています。PHP チュートリアルに興味のある友人に役立つことを願っています。

声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
PHPはユーザーのセッションをどのように識別しますか?PHPはユーザーのセッションをどのように識別しますか?May 01, 2025 am 12:23 AM

phpidentifiesauser'ssessionsingsinssessionCookiesIds.1)whensession_start()iscalled、phpgeneratesauniquesidstoredsored incoookienadphpsessidontheuser'sbrowser.2)thisidallowsphptortorieSessiondatadata fromthata

PHPセッションを保護するためのベストプラクティスは何ですか?PHPセッションを保護するためのベストプラクティスは何ですか?May 01, 2025 am 12:22 AM

PHPセッションのセキュリティは、次の測定を通じて達成できます。1。session_regenerate_id()を使用して、ユーザーがログインまたは重要な操作である場合にセッションIDを再生します。 2. HTTPSプロトコルを介して送信セッションIDを暗号化します。 3。Session_Save_Path()を使用して、セッションデータを保存し、権限を正しく設定するためのSecure Directoryを指定します。

PHPセッションファイルはデフォルトで保存されていますか?PHPセッションファイルはデフォルトで保存されていますか?May 01, 2025 am 12:15 AM

phpsessionFilesToredInthededirectoryspecifiedBysession.save_path、通常/tmponunix-likesystemsorc:\ windows \ temponwindows.tocustomizethis:1)uesession_save_path()tosetaCustomdirectory、ensuringit'swritadistradistradistradistradistra

PHPセッションからデータをどのように取得しますか?PHPセッションからデータをどのように取得しますか?May 01, 2025 am 12:11 AM

toretrievedatafrompsession、Startthessession withsession_start()andAccessvariablesshe $ _SessionArray.forexample:1)Startthessession:session_start()

セッションを使用してショッピングカートを実装するにはどうすればよいですか?セッションを使用してショッピングカートを実装するにはどうすればよいですか?May 01, 2025 am 12:10 AM

セッションを使用して効率的なショッピングカートシステムを構築する手順には、次のものがあります。1)セッションの定義と機能を理解します。セッションは、リクエスト全体でユーザーのステータスを維持するために使用されるサーバー側のストレージメカニズムです。 2)ショッピングカートに製品を追加するなど、基本的なセッション管理を実装します。 3)製品の量管理と削除をサポートし、高度な使用状況に拡大します。 4)セッションデータを持続し、安全なセッション識別子を使用することにより、パフォーマンスとセキュリティを最適化します。

PHPでインターフェイスをどのように作成して使用しますか?PHPでインターフェイスをどのように作成して使用しますか?Apr 30, 2025 pm 03:40 PM

この記事では、PHPでインターフェイスを作成、実装、および使用する方法について説明し、コード組織と保守性の利点に焦点を当てています。

crypt()とpassword_hash()の違いは何ですか?crypt()とpassword_hash()の違いは何ですか?Apr 30, 2025 pm 03:39 PM

この記事では、PHPのCrypt()とpassword_hash()の違いについて、パスワードハッシュの違いについて説明し、最新のWebアプリケーションの実装、セキュリティ、および適合性に焦点を当てています。

PHPのクロスサイトスクリプト(XSS)をどのように防ぐことができますか?PHPのクロスサイトスクリプト(XSS)をどのように防ぐことができますか?Apr 30, 2025 pm 03:38 PM

記事では、入力検証、出力エンコード、およびOWASP ESAPIやHTML浄化器などのツールを使用して、PHPのクロスサイトスクリプト(XSS)を防止します。

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衣類リムーバー

Video Face Swap

Video Face Swap

完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

ホットツール

PhpStorm Mac バージョン

PhpStorm Mac バージョン

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

EditPlus 中国語クラック版

EditPlus 中国語クラック版

サイズが小さく、構文の強調表示、コード プロンプト機能はサポートされていません

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

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

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

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

このプロジェクトは osdn.net/projects/mingw に移行中です。引き続きそこでフォローしていただけます。 MinGW: GNU Compiler Collection (GCC) のネイティブ Windows ポートであり、ネイティブ Windows アプリケーションを構築するための自由に配布可能なインポート ライブラリとヘッダー ファイルであり、C99 機能をサポートする MSVC ランタイムの拡張機能が含まれています。すべての MinGW ソフトウェアは 64 ビット Windows プラットフォームで実行できます。