1.安裝Nginx
apt-get install nginx
2.啓動Nginx
service nginx start
3.訪問服務器IP
若是看到「Welcome to nginx!」說明安裝好了。
4.安裝PHP
apt-get install php5-fpm
5.配置Nginx
找到下列代碼,去掉相應註釋
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
重啓服務
service nginx restart
或者
sudo service nginx reload
6.默認的網站根目錄在/var/www/html
vi /var/www/html/test.php
輸入如下內容,並保存
<?php
echo phpinfo();
?>
訪問網站IP/test.php,若是能夠看到phpinfo的信息說明php安裝成功。php
7.配置反向代理
upstream backend {
ip_hash;
server backend1.example.com;
server backend2.example.com;
server backend3.example.com;
server backend4.example.com;
}
location / {
proxy_pass http://backend;
}
注意:upstream 模塊要放在http模塊裏但要在server模塊以外html