Ubuntu上安装和配置nginx

@bingoogolapple 2015-03-23 17:23:59发表于 bingoogolapple/bingoogolapple.github.io LinuxPHP开发环境

安装nginx

sudo apt-get update
sudo apt-get install nginx

查看ip地址

ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'

安装mysql

sudo apt-get install mysql-server
sudo mysql_install_db
sudo mysql_secure_installation

安装PHP

sudo apt-get install php5-fpm php5-mysql
/etc/php5/fpm/php.ini中的 ;cgi.fix_pathinfo=1 改为 cgi.fix_pathinfo=0
sudo service php5-fpm restart

虚拟主机配置模板

server {
    listen 80;

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

    server_name server_domain_name_or_IP;

    location / {
        try_files $uri $uri/ =404;
    }

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

sudo service nginx restart