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安裝成功。
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模塊之外
