Home
Packages
Forums
Wiki
GitLab
Security
AUR
Download
コンテンツにスキップ
メインメニュー
メインメニュー
サイドバーに移動
非表示
案内
メインページ
目次
コミュニティに貢献
最近の出来事
おまかせ表示
特別ページ
交流
ヘルプ
貢献
最近の更新
最近の議論
新しいページ
統計
リクエスト
ArchWiki
検索
検索
表示
アカウント作成
ログイン
個人用ツール
アカウント作成
ログイン
Nginxのソースを表示
ページ
議論
日本語
閲覧
ソースを閲覧
履歴を表示
ツール
ツール
サイドバーに移動
非表示
操作
閲覧
ソースを閲覧
履歴を表示
全般
リンク元
関連ページの更新状況
ページ情報
表示
サイドバーに移動
非表示
←
Nginx
あなたには「このページの編集」を行う権限がありません。理由は以下の通りです:
この操作は、次のグループに属する利用者のみが実行できます:
登録利用者
。
このページのソースの閲覧やコピーができます。
{{Lowercase title}} [[Category:ウェブサーバー]] [[de:Nginx]] [[en:Nginx]] [[ru:Nginx]] [[zh-CN:Nginx]] [[Wikipedia:ja:nginx|nginx]] ("エンジンエックス"と発音します)は2005年から Igor Sysoev(ロシア)によって開発されている、フリーでオープンソースかつハイパフォーマンスな HTTP サーバーかつリバースプロクシで、IMAP/POP3 プロクシサーバーとしても機能します。Netcraft の [http://news.netcraft.com/archives/2014/01/03/january-2014-web-server-survey.html January 2014 Web Server Survey] によると、世界中の全てのドメインのうち 14.4% は Nginx によってホストされています。一方、[[Apache]] は41.64%をホストしています。Nginx は主に、その安定性・多機能・単純な設定・低リソース消費によって知られています。 == インストール == [[公式リポジトリ]]から {{Pkg|nginx}} パッケージを[[Pacman|インストール]]できます。 ''Ruby on Rails'' のためにインストールするには、[[Ruby on Rails#Rails パーフェクトセットアップ]]を参照してください。 セキュリティを向上させるために chroot によるインストールをするには、[[#chroot でインストール]] を参照してください。 == サービスの開始 == Nginx サービスを走らせるには: # systemctl start nginx スタートアップ時に Nginx サービスを起動するには: # systemctl enable nginx http://127.0.0.1 にデフォルトで表示されるページは: /usr/share/nginx/html/index.html == 設定 == nginx における最初の手順は [http://nginx.org/en/docs/beginners_guide.html 公式のビギナーズガイド] で説明されています。{{ic|/etc/nginx/}} にあるファイルを編集することで Nginx の設定ができます。メインの設定ファイルは {{ic|/etc/nginx/nginx.conf}} です。 より詳しい解説はこちら: 公式の [http://nginx.org/en/docs/ ドキュメント] にある [http://wiki.nginx.org/Configuration Nginx Configuration Examples]。 === 一般設定 === {{ic|worker_processes}} の適当な値を探って下さい。この設定は最終的に nginx が受け入れる接続の数と利用できるプロセスの数を定義します。通常、システムのハードウェアのスレッド数にすると良いでしょう。また、バージョン 1.3.8 と 1.2.5 から {{ic|worker_processes}} には {{ic|auto}} と設定することができ、最適な値を自動的に検出します ([http://nginx.org/en/docs/ngx_core_module.html#worker_processes ソース])。 nginx が受け入れる最大接続数は {{ic|1=max_clients = worker_processes * worker_connections}} で計算できます。 ==== サーバーブロック ==== {{ic|server}} ブロックを使うことで複数のドメインを利用することができます。"バーチャルホスト"とも呼ばれますが、これは [[Apache]] の用語です。{{ic|server}} ブロックの利用方法は [http://wiki.nginx.org/ServerBlockExample Apache] とは異なっています。 以下の例では2つのドメインの接続をサーバーが待機します: {{ic|domainname1.dom}} と {{ic|domainname2.dom}}: {{hc|/etc/nginx/nginx.conf|<nowiki> ... server { listen 80; server_name domainname1.dom; root /usr/share/nginx/domainname1.dom/html; location / { index index.php index.html index.htm; } } server { listen 80; server_name domainname2.dom; root /usr/share/nginx/domainname2.dom/html; ... } ... }</nowiki>}} {{ic|nginx.service}} を[[再起動]]して変更を適用します。 クライアントからの接続時にこれらのドメイン名を解決するには、[[BIND]] や [[dnsmasq]] などのDNSサーバーを設定する必要があります。 ローカルマシンでバーチャルホストをテストするには、{{ic|/etc/hosts}} ファイルにバーチャルネームを追加してください: 127.0.0.1 domainname1.dom 127.0.0.1 domainname2.dom ==== SSL ==== SSL を使用するには、{{pkg|openssl}} をインストールする必要があります。 自己署名証明書を作成してください (キーのサイズや効力の日数は変更できます): # cd /etc/nginx/ # openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out cert.key # chmod 600 cert.key # openssl req -new -key cert.key -out cert.csr # openssl x509 -req -days 365 -in cert.csr -signkey cert.key -out cert.crt HTTPS サーバーの server ブロックを以下のように修正してください: {{hc|/etc/nginx/nginx.conf|<nowiki> server { listen 443 ssl; server_name localhost; ssl_certificate cert.crt; ssl_certificate_key cert.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; root /usr/share/nginx/html; location / { index index.html index.htm index.php; } }</nowiki>}} {{ic|nginx.service}} を再起動して変更を適用します。 === FastCGI === FastCGI、または FCGI はウェブサーバーでインタラクティブなプログラムを動作させるためのプロトコルです。FastCGI は Common Gateway Interface (CGI) の変種で、ウェブサーバーと CGI プログラムのオーバーヘッドを減らすよう設計されていて、サーバーはより多くのウェブページのリクエストを一度に捌くことができます。 Nginx には FastCGI が組み込まれており多くの外部ツールが動きます、例えば Perl、[[PHP]]、[[Python]] など。これらを使うためにはまず FastCGI サーバーを動かす必要があります。 ==== PHP を動かす ==== PHP のために FastCGI サーバーを動かす方法は複数あります。ここでは推奨方法として php-fpm を使う方法を記載しています。 ===== 手順1: PHP の設定 ===== {{Pkg|php}} をインストールしてください。{{ic|/etc/php/php.ini}} の中にある {{Ic|open_basedir}} に PHP ファイルが含まれているベースディレクトリを ({{ic|/srv/http/}} や {{ic|/usr/share/webapps/}} のような感じで)指定しなくてはなりません: open_basedir = /usr/share/webapps/:/srv/http/:/home/:/tmp/:/usr/share/pear/ そうしたら必要なモジュールを設定しましょう。例えば sqlite3 を使うなら {{Pkg|php-sqlite}} をインストールして、{{ic|/etc/php/php.ini}} の次の行をアンコメントして有効にします: extension=sqlite3.so {{Note|chroot 環境で nginx を動かしている場合 (chroot は {{ic|/srv/nginx-jail}} で、ウェブページは {{ic|/srv/nginx-jail/www}}) です。{{ic|/etc/php/php-fpm.conf}} ファイルを編集して {{ic|chroot /srv/nginx-jail}} と {{ic|1=listen = /srv/nginx-jail/run/php-fpm/php-fpm.sock}} ディレクティブを pool セクション (デフォルトは {{ic|[www]}}) の中に記述する必要があります。ソケットファイルのディレクトリが存在しない場合は作成してください。}} ====== MariaDB ====== [[MariaDB]] で説明されているようにして MySQL/MariaDB を設定してください。 {{ic|/etc/php/php.ini}} の以下の行の [http://www.php.net/manual/en/mysqlinfo.api.choosing.php 少なくともどれか一つ] をアンコメント: extension=pdo_mysql.so extension=mysqli.so {{Warning|PHP 5.5 から、{{ic|mysql.so}} は [http://www.php.net/manual/de/migration55.deprecated.php 廃止] されログファイルにエラーが表示されます。}} ウェブスクリプトのために最小権限の MySQL ユーザーを追加することができます。また、{{ic|/etc/mysql/my.cnf}} を編集して {{ic|skip-networking}} 行をアンコメントすると MySQL サーバーはローカルホストからしかアクセスできなくなります。変更を適用するには MySQL を再起動する必要があります。 {{Tip|データベースを利用するために [[phpMyAdmin]], [[Adminer]], {{Pkg|mysql-workbench}} などのツールをインストールしても良いでしょう。}} ===== 手順2: php-fpm ===== * http://php-fpm.org {{Pkg|php-fpm}} をインストールします: # pacman -S php-fpm 設定ファイルは {{ic|/etc/php/php-fpm.conf}} です。 サービスを動かします: # systemctl start php-fpm {{Ic|php-fpm}} をスタートアップ時に有効にします: # systemctl enable php-fpm.service ===== 手順3: Nginx の設定 ===== それぞれの {{ic|server}} ブロックの中の {{ic|location}} ブロックに PHP アプリケーションを次のように記述します: location ~ \.php$ { fastcgi_pass unix:/run/php-fpm/php-fpm.sock; fastcgi_index index.php; include fastcgi.conf; } {{Ic|/etc/nginx/php.conf}} を作って設定をそこに書く場合、このファイルを {{Ic|server}} ブロックに入れて下さい。 server = { ... include php.conf; ... } .html や .htm ファイルを PHP として処理したい場合は、以下のようにしてください: location ~ \.(php|html|htm)$ { fastcgi_pass unix:/run/php-fpm/php-fpm.sock; fastcgi_index index.php; include fastcgi.conf; } 拡張子が .php でないファイルを php-fpm で動かすことを {{Ic|/etc/php/php-fpm.conf}} で有効にする必要があります: security.limit_extensions = .php .html .htm 設定を変えた後は php-fpm デーモンを再起動してください。 # systemctl restart php-fpm {{Note|{{Ic|fastcgi_pass}} 引数に'''注意を払って下さい'''、FastCGI サーバーの設定ファイルで定義された TCP や Unix ソケットでなくてはなりません。'''デフォルトの''' {{Ic|php-fpm}} (Unix) ソケットは fastcgi_pass unix:/run/php-fpm/php-fpm.sock; '''デフォルトの代わりに'''、通常の TCP ソケットを使うこともできます fastcgi_pass 127.0.0.1:9000; ただし Unix ドメインソケットの方が高速です。}} Nginx のための FastCGI 設定がある {{Ic|fastcgi.conf}} か {{Ic|fastcgi_params}} が含まれていますが、後者は使われなくなりました。これらのファイルは Nginx をインストールしたときに作られます。 最後に、Nginx が動作している場合は再起動してください: # systemctl restart nginx FastCGI をテストしたい場合は、{{ic|/usr/share/nginx/html/index.php}} を次の内容で作成して <?php phpinfo(); ?> ブラウザで http://127.0.0.1/index.php を開いて下さい。 以下は実際の設定例です。例の中では {{ic|root}} パスは {{ic|server}} の下に直接指定されており (デフォルト設定のように) {{ic|location}} の中には置いていません。 server { listen 80; server_name localhost; root /usr/share/nginx/html; location / { index index.html index.htm index.php; } location ~ \.php$ { #fastcgi_pass 127.0.0.1:9000; (depending on your php-fpm socket configuration) fastcgi_pass unix:/run/php-fpm/php-fpm.sock; fastcgi_index index.php; include fastcgi.conf; } } ==== CGI を動かす ==== この実装は CGI アプリケーションに必要です。 ===== 手順1: fcgiwrap ===== {{Pkg|fcgiwrap}} をインストールしてください。 設定ファイルは {{ic|/usr/lib/systemd/system/fcgiwrap.socket}} です。 [[systemd]] の ''fcgiwrap.socket'' を有効化・起動します。 この systemd ユニットファイルは現在 [https://bugs.archlinux.org/task/31696 ArchLinux のタスクページ]で議論されています。思い通りに動くか確認するためにユニットファイルを自分で検査すると良いでしょう。 ====== マルチワーカースレッド ====== 複数のワーカースレッドを生成したい場合は、{{AUR|multiwatch}} を使用するのが推奨されています。これはクラッシュした子スレッドの再起動の面倒をみてくれます。multiwatch は systemd が作成したソケットを管理できないため、unix ソケットを作成するには {{ic|spawn-fcgi}} を使う必要がありますが、ユニットファイルから直接実行した場合は fcgiwrap には問題が生じません。 {{ic|/usr/lib/systemd/system/fcgiwrap.service}} から {{ic|/etc/systemd/system/fcgiwrap.service}} にユニットファイルをコピーして (存在する場合は {{ic|fcgiwrap.socket}} ユニットも)、{{ic|ExecStart}} 行を必要に応じて修正してください。以下は {{AUR|multiwatch}} を使用するユニットファイルです。{{ic|fcgiwrap.socket}} が実行中だったり有効になっていないことを確認してください、このユニットと衝突してしまうからです: {{hc|/etc/systemd/system/fcgiwrap.service|2= [Unit] Description=Simple CGI Server After=nss-user-lookup.target [Service] ExecStartPre=/bin/rm -f /run/fcgiwrap.socket ExecStart=/usr/bin/spawn-fcgi -u http -g http -s /run/fcgiwrap.sock -n -- /usr/bin/multiwatch -f 10 -- /usr/sbin/fcgiwrap ExecStartPost=/usr/bin/chmod 660 /run/fcgiwrap.sock PrivateTmp=true Restart=on-failure [Install] WantedBy=multi-user.target }} {{ic|-f 10}} は生成する子スレッドの数に変更してください。 {{Warning|The ExecStartPost line is required because of strange behaviour I'm seeing when I use the {{ic|-M 660}} option for {{ic|spawn-fcgi}}. The wrong mode is set. This may be a bug?}} ===== 手順2: Nginx の設定 ===== CGI ウェブアプリケーションを置くそれぞれの {{Ic|server}} ブロックには以下のような {{Ic|location}} ブロックを記述します: location ~ \.cgi$ { root /path/to/server/cgi-bin; fastcgi_pass unix:/run/fcgiwrap.sock; include fastcgi.conf; } {{Ic|fcgiwrap}} の'''デフォルト''' (Unix) ソケットは ''/run/fcgiwrap.sock'' です。 == chroot でインストール == [[chroot]] に Nginx をインストールすることでセキュリティレイヤーを追加することができます。セキュリティを最大限に高めるために、Nginx サーバーを動かすのに必要なファイルだけを入れて、全てのファイルは出来る限り最小限の権限にします。例えば、なるべく root が所有するようにして、{{ic|/usr/bin}} などのディレクトリは読み書きできないようにするなど。 Arch はデフォルトでサーバーを実行するための {{ic|http}} ユーザーとグループが設定されています。chroot は {{ic|/srv/http}} で動作させます。 この牢獄を作るための perl スクリプトが [https://gist.github.com/4365696 jail.pl gist] にあります。このスクリプトを使用するか、またはこの記事の指示に従って作成するか選ぶことができます。スクリプトは root で実行してください。変更を適用する前に行をアンコメントする必要があります。 === 必要なデバイスを作成 === Nginx には {{ic|/dev/null}}, {{ic|/dev/random}}, {{ic|/dev/urandom}} が必要です。これらを chroot にインストールするために {{ic|/dev/}} フォルダを作成してデバイスを mknod で追加します。chroot が危険になったときでも、攻撃者が {{ic|/dev/sda1}} などの重要なデバイスにアクセスするには chroot から脱出しなくてはならないようにするために、{{ic|/dev/}} を全てマウントはしません。 {{Tip|mknod の引数については {{ic|man mknod}} や {{ic|<nowiki>ls -l /dev/{null,random,urandom}</nowiki>}} を見て下さい。}} # export JAIL=/srv/http # mkdir $JAIL/dev # mknod -m 0666 $JAIL/dev/null c 1 3 # mknod -m 0666 $JAIL/dev/random c 1 8 # mknod -m 0444 $JAIL/dev/urandom c 1 9 === 必要なフォルダを作成 === Nginx を適切に実行するためにはたくさんのファイルが必要になります。それらをコピーする前に、ファイルを保存するためのフォルダを作成してください。ここでは Nginx のドキュメントルートが {{ic|/srv/http/www}} であると仮定します。 # mkdir -p $JAIL/etc/nginx/logs # mkdir -p $JAIL/usr/{lib,bin} # mkdir -p $JAIL/usr/share/nginx # mkdir -p $JAIL/var/{log,lib}/nginx # mkdir -p $JAIL/www/cgi-bin # mkdir -p $JAIL/{run,tmp} # cd $JAIL; ln -s usr/lib lib {{Note|64ビットのカーネルを使っている場合 {{ic|usr/lib}} に {{ic|lib64}} と {{ic|usr/lib64}} のシンボリックリンクを作成する必要があります: {{ic|cd $JAIL; ln -s usr/lib lib64}} と {{ic|cd $JAIL/usr; ln -s lib lib64}}。}} そして {{ic|$JAIL/tmp}} と {{ic|$JAIL/run}} を tmpfs でマウントします。攻撃者が RAM を全て喰いつくせないようにサイズを制限すると良いでしょう。 # mount -t tmpfs none $JAIL/run -o 'noexec,size=1M' # mount -t tmpfs none $JAIL/tmp -o 'noexec,size=100M' 再起動してもマウントが維持されるように、以下のエントリを {{ic|/etc/fstab}} に追加します: {{hc|/etc/fstab|<nowiki> tmpfs /srv/http/run tmpfs rw,noexec,relatime,size=1024k 0 0 tmpfs /srv/http/tmp tmpfs rw,noexec,relatime,size=102400k 0 0 </nowiki>}} === chroot に移住 === まず平易なファイルをコピーします。 # cp -r /usr/share/nginx/* $JAIL/usr/share/nginx # cp -r /usr/share/nginx/html/* $JAIL/www # cp /usr/bin/nginx $JAIL/usr/bin/ # cp -r /var/lib/nginx $JAIL/var/lib/nginx そして必要なライブラリをコピーします。ldd を使ってライブラリを確認して適当な場所にコピーして下さい。ハードリンクよりはコピーが推奨されます。攻撃者が書き込み権限を得たときに本当のシステムファイルが破壊されたり改変される可能性があるためです。 {{hc|$ ldd /usr/bin/nginx|<nowiki> linux-vdso.so.1 (0x00007fffc41fe000) libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007f57ec3e8000) libcrypt.so.1 => /usr/lib/libcrypt.so.1 (0x00007f57ec1b1000) libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007f57ebead000) libm.so.6 => /usr/lib/libm.so.6 (0x00007f57ebbaf000) libpcre.so.1 => /usr/lib/libpcre.so.1 (0x00007f57eb94c000) libssl.so.1.0.0 => /usr/lib/libssl.so.1.0.0 (0x00007f57eb6e0000) libcrypto.so.1.0.0 => /usr/lib/libcrypto.so.1.0.0 (0x00007f57eb2d6000) libdl.so.2 => /usr/lib/libdl.so.2 (0x00007f57eb0d2000) libz.so.1 => /usr/lib/libz.so.1 (0x00007f57eaebc000) libGeoIP.so.1 => /usr/lib/libGeoIP.so.1 (0x00007f57eac8d000) libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007f57eaa77000) libc.so.6 => /usr/lib/libc.so.6 (0x00007f57ea6ca000) /lib64/ld-linux-x86-64.so.2 (0x00007f57ec604000)</nowiki>}} # cp /lib64/ld-linux-x86-64.so.2 $JAIL/lib {{ic|/usr/lib}} の中にあるファイルについては次のワンライナーが使えます: {{bc|<nowiki># cp $(ldd /usr/bin/nginx | grep /usr/lib | sed -sre 's/(.+)(\/usr\/lib\/\S+).+/\2/g') $JAIL/usr/lib</nowiki>}} {{Note|{{ic|linux-vdso.so}} をコピーしないでください – 実際のライブラリではなく {{ic|/usr/lib}} には存在しません。64ビット環境の場合 {{ic|ld-linux-x86-64.so}} も {{ic|/lib64}} にあるように表示されます。}} 必要なライブラリとシステムファイル以外のファイルをコピーします。 {{bc|# cp /usr/lib/libnss_* $JAIL/usr/lib # cp -rfvL /etc/{services,localtime,nsswitch.conf,nscd.conf,protocols,hosts,ld.so.cache,ld.so.conf,resolv.conf,host.conf,nginx} $JAIL/etc}} Create restricted user/group files for the chroot. This way only the users needed for the chroot to function exist as far as the chroot knows, and none of the system users/groups are leaked to attackers should they gain access to the chroot. {{hc|$JAIL/etc/group| http:x:33: nobody:x:99: }} {{hc|$JAIL/etc/passwd| http:x:33:33:http:/:/bin/false nobody:x:99:99:nobody:/:/bin/false }} {{hc|$JAIL/etc/shadow| http:x:14871:::::: nobody:x:14871:::::: }} {{hc|$JAIL/etc/gshadow| http::: nobody::: }} # touch $JAIL/etc/shells # touch $JAIL/run/nginx.pid Finally make set very restrictive permissions. As much as possible should be owned by root and set unwritable. # chown -R root:root $JAIL/ # chown -R http:http $JAIL/www # chown -R http:http $JAIL/etc/nginx # chown -R http:http $JAIL/var/{log,lib}/nginx # chown http:http $JAIL/run/nginx.pid # find $JAIL/ -gid 0 -uid 0 -type d -print | xargs sudo chmod -rw # find $JAIL/ -gid 0 -uid 0 -type d -print | xargs sudo chmod +x # find $JAIL/etc -gid 0 -uid 0 -type f -print | xargs sudo chmod -x # find $JAIL/usr/bin -type f -print | xargs sudo chmod ug+rx # find $JAIL/ -group http -user http -print | xargs sudo chmod o-rwx # chmod +rw $JAIL/tmp # chmod +rw $JAIL/run If your server will bind port 80 (or any port 0-1024), give the chrooted executable permission to bind these ports without root. # setcap 'cap_net_bind_service=+ep' $JAIL/usr/bin/nginx === nginx.service を変更して chroot を起動 === Before modifying the nginx.service unit file, it may be a good idea to copy it to {{ic|/etc/systemd/system/}} since the unit files there take priority over those in {{ic|/usr/lib/systemd/system/}}. This means upgrading nginx would not modify your custom .service file. # cp /usr/lib/systemd/system/nginx.service /etc/systemd/system/nginx.service The systemd unit must be changed to start up Nginx in the chroot, as the http user, and store the pid file in the chroot {{Note|I'm not sure if the pid file needs to be stored in the chroot jail.}} {{hc|/etc/systemd/system/nginx.service|<nowiki> [Unit] Description=A high performance web server and a reverse proxy server After=syslog.target network.target [Service] Type=forking PIDFile=/srv/http/run/nginx.pid ExecStartPre=/usr/bin/chroot --userspec=http:http /srv/http /usr/bin/nginx -t -q -g 'pid /run/nginx.pid; daemon on; master_process on;' ExecStart=/usr/bin/chroot --userspec=http:http /srv/http /usr/bin/nginx -g 'pid /run/nginx.pid; daemon on; master_process on;' ExecReload=/usr/bin/chroot --userspec=http:http /srv/http /usr/bin/nginx -g 'pid /run/nginx.pid; daemon on; master_process on;' -s reload ExecStop=/usr/bin/chroot --userspec=http:http /srv/http /usr/bin/nginx -g 'pid /run/nginx.pid;' -s quit [Install] WantedBy=multi-user.target</nowiki>}} {{Note|Upgrading nginx with pacman will not upgrade the chrooted nginx installation. You have to take care of the updates manually by repeating some of the steps above. Do not forget to also update the libraries it links against. }} You can now safely get rid of the non-chrooted nginx installation. # pacman -Rsc nginx If you do not remove the non-chrooted nginx installation, you may want to make sure that the running nginx process is in fact the chrooted one. You can do so by checking where {{ic|/proc/{PID}/root}} symmlinks to. If should link to {{ic|/srv/http}} instead of {{ic|/}}. # ps -C nginx | awk '{print $1}' | sed 1d | while read -r PID; do ls -l /proc/$PID/root; done == トラブルシューティング == === 設定の確認 === # nginx -t 結果: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful === ローカル IP へのアクセスが localhost にリダイレクトされる === Arch Linux [https://bbs.archlinux.org/viewtopic.php?pid=780561#p780561 フォーラム]からの解決法があります。 {{ic|/etc/nginx/nginx.conf}} を開き、"server_name localhost" の前の # を取り除き、以下を付け加えます: server_name_in_redirect off; デフォルトでは、nginx は設定にある server_name へのリクエストをすべてリダイレクトします。 === Error: 403 (Permission error) === This is most likely a permission error. Are you sure whatever user configured in the Nginx configuration is able to read the correct files? If the files are located within a home directory, (e.g. {{ic|/home/arch/public/webapp}}) and you are sure the user running Nginx has the right permissions (you can temporarily chmod all the files to 777 in order to determine this), {{ic|/home/arch}} might be '''chmod 750''', simply {{Ic|chmod}} it to ''751'', and it should work. '''If you have changed your document root''' If you are sure that permissions are as they should be, make sure that your document root directory is not empty. Try creating index.html in there. === Error: 404 (Pathinfo error) === いくつかのフレームワーク (thinkphp、cakephp など)や CMS では pathinfo が必要です。 1. {{ic|/etc/php/php.ini}} ファイルを開き、次のように付け加えます cgi.fix_pathinfo=1 2. {{ic|/etc/nginx/nginx.conf}} を開き、次の部分をコメントアウトします location ~ \.php$ { ... } を #location ~ \.php$ { #... #} そして以下を加えます location ~ ^(.+\.php)(.*)$ { root /srv/http/nginx; fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; #fastcgi_pass 127.0.0.1:9000; #Un-comment this and comment "fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;" if you are not using php-fpm. fastcgi_index index.php; set $document_root2 $document_root; if ($document_root2 ~ "^(.*\\\\).*?[\\\\|\/]\.\.\/(.*)$") { set $document_root2 $1$2; } if ($document_root2 ~ "^(.*\\\\).*?[\\\\|\/]\.\.\/(.*)$") { set $document_root2 $1$2; } if ($document_root2 ~ "^(.*\\\\).*?[\\\\|\/]\.\.\/(.*)$") { set $document_root2 $1$2; } if ($document_root2 ~ "^(.*\\\\).*?[\\\\|\/]\.\.\/(.*)$") { set $document_root2 $1$2; } if ($document_root2 ~ "^(.*\\\\).*?[\\\\|\/]\.\.\/(.*)$") { set $document_root2 $1$2; } fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_param SCRIPT_FILENAME $document_root2$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root2$fastcgi_path_info; include fastcgi_params; fastcgi_param DOCUMENT_ROOT $document_root2; } try_files を使う方法もあります: server { .. root /usr/share/nginx/html; index index.php; location / { try_files $uri $uri/ /index.php?$args; } } === Error: The page you are looking for is temporarily unavailable. Please try again later. === FastCGI サーバーが動作していないか、ソケットが間違ったパーミッションに設定されています。 === Error: No input file specified === おそらくスクリプトのフルパスを含んだ SCRIPT_FILENAME がありません。 nginx の設定 (fastcgi_param SCRIPT_FILENAME) が完全でも、このエラーは php が requestd スクリプトをロードできないことを意味しています。これは単純にパーミッションの問題であることが普通で、root で php-cgi を実行するか # spawn-fcgi -a 127.0.0.1 -p 9000 -f /usr/bin/php-cgi php-cgi を起動するグループとユーザーを作成する必要があります。例えば: # groupadd www # useradd -g www www # chmod +w /srv/www/nginx/html # chown -R www:www /srv/www/nginx/html # spawn-fcgi -a 127.0.0.1 -p 9000 -u www -g www -f /usr/bin/php-cgi 他の可能性としては、{{ic|nginx.conf}} 内の "location ~ \.php$" セクションの "root" 引数が間違っていることがありえます。"root" が同じサーバーの "location /" と同じディレクトリを示しているか確認してください。もしくは root をグローバルに設定するには、location セクションで定義しないでください。 Also keep in mind that your php script path was defined as {{ic|/srv/http}} by default using the variable "open_basedir" in {{ic|/etc/php/php.ini}}; you can change them if you need. Also notice that not only php script should have read permission, but also the entire directory structure should have execute permission so that PHP user can traverse the path. === Error: FastCGI で空のページが表示される === access.log にエラーが表示されず、コード200が返されるのに以下のような空のページが表示される場合: <html> <head></head> <body></body> </html> [http://beutelevision.com/blog2/2013/08/26/nginx-with-php-fpm-generating-blank-page/ Thomas Beutel のブログ] に書かれた解決方法: {{ic|/etc/nginx/nginx.conf}} を編集して php の {{ic|location}} セクションに {{ic|fastcgi_param}} という行を追加: location ~ \.php$ { ... include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; ... } php_fpm では PHP ファイルのパスを認識するために以上のように設定する必要があります。 == 参照 == * [http://nginx.org/ Nginx 公式サイト] * [http://calomel.org/nginx.html Nginx HowTo] * [http://wiki.gotux.net/config:nginx Easy Config Files] * [http://www.tecmint.com/install-nginx-php-mysql-with-mariadb-engine-and-phpmyadmin-in-arch-linux/ Installing LEMP (Nginx, PHP, MySQL with MariaDB engine and PhpMyAdmin) in Arch Linux]
このページで使用されているテンプレート:
テンプレート:AUR
(
ソースを閲覧
)
テンプレート:Bc
(
ソースを閲覧
)
テンプレート:Hc
(
ソースを閲覧
)
テンプレート:Ic
(
ソースを閲覧
)
テンプレート:Lowercase title
(
ソースを閲覧
)
テンプレート:Man
(
ソースを閲覧
)
テンプレート:Note
(
ソースを閲覧
)
テンプレート:Pkg
(
ソースを閲覧
)
テンプレート:Tip
(
ソースを閲覧
)
テンプレート:Warning
(
ソースを閲覧
)
Nginx
に戻る。
検索
検索
Nginxのソースを表示
話題を追加