1. 程式人生 > >阿里雲伺服器部署應用環境(nginx伺服器)

阿里雲伺服器部署應用環境(nginx伺服器)

阿里雲伺服器的配置

1、開啟阿里雲官網,登入上自己的賬號,點選控制檯

2、點選左側的雲伺服器ECS

3、點選例項

4、選擇您所購買的伺服器的區域,選擇你要配置的伺服器,點選遠端連線。

5、輸入管理終端密碼。(如果是第一次登入,系統會告訴你初始密碼)

6、登入雲伺服器

       1.輸入登入名(一般為root)

       2.輸入密碼(購買伺服器時,自己設定的)

       3.按enter鍵 登入

7、開始配置

1. 安裝及啟動nginx

輸入yum install nginx命令進行nginx的安裝,當需要確認時輸入”y“確認。
yum install nginx

安裝完成後,輸入service nginx start啟動nginx服務。

service nginx start

輸入wget http://127.0.0.1測試nginx服務。

wget http://127.0.0.1


2. 安裝PHP及相應元件

輸入yum install php php-fpm命令進行PHP的安裝,當需要確認時輸入”y“確認。
yum install php php-fpm

輸入service php-fpm start啟動php-fpm服務,並使用命令cat /etc/php-fpm.d/www.conf |grep -i 'listen ='檢視php-fpm配置。

service php-fpm start

cat /etc/php-fpm.d/www.conf |grep -i 'listen ='

上圖可見php-fpm的預設配置的監聽埠為9000,現在需要修改配置將php解析的請求轉發到127.0.0.0:9000處理即可。

使用命令nginx -t查詢nginx配置檔案,並使用vi命令修改該配置檔案:

nginx -t
vi /etc/nginx/nginx.conf


在配置檔案中找到以下片段,修改紅色部分。(按任意鍵(或者i鍵)行文字編輯,以“#”開頭的為註釋行。編輯完成後,按Esc鍵,在輸入:wq,儲存並退出)

server {
  listen       80;
  root   /usr/share/nginx/html;
server_name localhost; #charset koi8-r; #access_log /var/log/nginx/log/host.access.log main; location / { index index.html index.htm; } #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; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ .php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }

修改後儲存,輸入service nginx restart重啟nginx服務。

service nginx restart

在web目錄下建立index.php:

vi /usr/share/nginx/html/index.php

用vi命令進行編輯,寫入以下資訊:

Hello World


在瀏覽器中,訪問伺服器公網IP+php網頁名稱檢視環境配置是否成功,如果頁面可以顯示“hello world”,說明配置成功。