Nginxで初めてサーバ設定(centos)
とりあえずググればなんとかなったけどいちいちググるのもめんどくさいのでここに集約。
Nginx使うことはしばらくなさそうだし。
バーチャルホスト
view /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name 127.0.0.1;#charset koi8-r;
#access_log /var/log/nginx/log/localhost.access.log main;location / {
root /var/www;
index index.php;
}#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/html;
}# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
root /var/www;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/$fastcgi_script_name;
include fastcgi_params;
}# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}server {
listen 80 default_server;
server_name www.XXXXX.jp;
#server_name 153.XXXXX;
allow 153.~XXXXX;access_log /var/log/nginx/XXXXX.access.log main;
location / {
root /var/www/html;
index index.php index.html;
# auth_basic "Restricted";
# auth_basic_user_file /var/www/html/.htpasswd;
}
location ~ \.php$ {
root /var/www/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name;
include fastcgi_params;
}
}
リダイレクト設定。
下記はWWWありなしを統一。(元々ありなしどちらもアクセス可能前提)
vi /etc/nginx/nginx.conf
server {
server_name XXXXX.jp;
rewrite ^(.*)$ http://www.XXXXX.jp$1 last;
}
★vhostのテスト
/etc/init.d/nginx configtest
最後にnginxの再起動
/etc/init.d/nginx reload
サーバーのログ
/var/log/nginx
どうもNginxでPHPインストールするときは
良く分からないけど両方入れておいた。
rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -ivh http://rpms.famillecollet.com/enterprise/6/remi/x86_64/remi-release-6.6-2.el6.remi.noarch.rpmyum -y install --enablerepo=remi --enablerepo=remi-php55 php php-opcache php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug
★PHP fpm インストール
★PHP fpm スタート
service php-fpm start
★自動起動
chkconfig php-fpm on