初期設定
sudo apt-get -y update
sudo apt-get -y upgrade
apt-cache show nginx
- デフォルトだと古いので
sudo vi /etc/apt/sources.list.d/nginx.list
にて以下を追加
deb http://nginx.org/packages/ubuntu/ precise nginx
deb-src http://nginx.org/packages/ubuntu/ precise nginx
apt-cache show nginx
インストール
- python-software-propertiesのインストール
sudo apt-get install python-software-properties
sudo apt-get install -y php5 php5-mysql php-devel php-cli php-mbstring php-gdxml
sudo apt-get install -y php5-fpm
sudo apt-get install nginx -y
sudo apt-get install -y mysql-server
sudo apt-get -y install sysv-rc-conf
sudo curl get.fuelphp.com/oil | sh
とりあえず、Fuelphpのプロジェクト作成
cd /usr/share/nginx/html/
sudo oil create [xxx-prject]
設定
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/[domain_name]
sudo vi /etc/nginx/sites-available/www.tech-event.info
upstream php {
server unix:/var/run/php5-fpm.sock;
}
server {
listen 80;
root /usr/share/nginx/html/[domain_name]/public/;
index index.php index.html index.htm;
server_name [domain_name];
location / {
try_files $uri $uri/ =404;
}
# PHP
location ~* \.php$ {
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
include /etc/nginx/site-enabled/*;
}
}
sudo ln -s /etc/nginx/sites-available/www.tech-event.info /etc/nginx/sites-enabled/
sudo chown www-data:www-data /var/run/php5-fpm.sock
再起動
sudo service nginx restart
sudo service php5-fpm restart
エラーメッセージに対しての対応
sudo: unable to resolve host
対処方法
202.XXX.YYY.ZZZ [hostname]
アクセスしても動作しない場合は/var/log/nginx/error.log
を見ること
tail /var/log/nginx/error.log
connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstrea
- 権限がないので
chown
で適切なユーザーに設定を行う。