!!!公式
http://nginx.org/en/linux_packages.html
!!インストール
/etc/yum.repo.d/nginx.conf
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
yum install nginx
!!設定
/etc/nginx/conf.d/
に設定を書く。
!userdir的な設定
# for UserDir
server {
listen 82;
location ~ ^/~(.+?)(/.*)?$ {
alias /home/$1/public_html$2;
index index.html index.htm;
autoindex on;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
}
!ディレクトリの判定順位
https://server-setting.info/centos/nginx-location-check.html#location_2
location /sample/ {
# /sample/ で始まる全てのURIに一致します。
# しかし、以降の正規表現や文字列が長いものが優先的に処理されます。
[ configuration A ]
}
location ~ ^/sample/ {
# /sample/ で始まる全てのURIに一致します。
# しかし、以降の ^~ が優先的に処理されます。
[ configuration B ]
}
location ^~ /sample/ {
# /sample/ で始まる全てのURIに一致します。
# これは、もしURIがこの条件に一致したら、以降いかなるチェックも(正規表現であっても)
# チェックされないことを意味します。
[ configuration C ]
}
!!nginxのリクエスト処理順
https://tengine.taobao.org/nginx_docs/ja/docs/http/request_processing.html
server {
.....
}
を処理する場合、ヘッダ情報からどのserverに処理を振り分けるか判断する。
例えば、ポート番号とかサーバ名とか。
どれにもマッチしない場合はデフォルトサーバに振り分けられる。
{{category2 OS,Linux}}