centOS 7 lnmp環境搭建

1.安裝nginx

[python] view plain copy
 在CODE上查看代碼片派生到我的代碼片
  1. yum install yum-priorities -y  
  2. wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm  
  3. rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm  
  4. yum install nginx  

[python] view plain copy
 在CODE上查看代碼片派生到我的代碼片
  1. systemctl start nginx.service #啓動nginx  
  2. systemctl stop nginx.service #停止  
  3. systemctl restart nginx.service #重啓  
  4. systemctl enable nginx.service #設置開機啓動   

2.更改nginx端口號(根據自己需求)

[python] view plain copy
 在CODE上查看代碼片派生到我的代碼片
  1. cd /etc/nginx/conf.d/  
  2. vim default.conf  
  3. 把listen 80改成listen 81  
[python] view plain copy
 在CODE上查看代碼片派生到我的代碼片
  1. systemctl restart nginx.service #重啓nginx  


3.訪問http://ip:81即可看到nginx首頁

4.下一步安裝php-fpm
[python] view plain copy
 在CODE上查看代碼片派生到我的代碼片
  1. yum install php-fpm  
[python] view plain copy
 在CODE上查看代碼片派生到我的代碼片
  1. systemctl start php-fpm.service #啓動php-fpm  
  2. systemctl enable php-fpm.service #設置開機啓動  

5.更改nginx配置文件識別php

 vi /etc/nginx/conf.d/default.conf,把之前的#給去掉就可以了,順手改一下fastcgi_param

[python] view plain copy
 在CODE上查看代碼片派生到我的代碼片
  1. location ~ \.php$ {  
  2.     root           html;  
  3.     fastcgi_pass   127.0.0.1:9000;  
  4.     fastcgi_index  index.php;  
  5.     fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html/$fastcgi_script_name;  
  6.     include        fastcgi_params;  
  7. }  

6.

在 /usr/share/nginx/html中新建一個test.php  <?php echo 123;?>

訪問http://ip:81/test.php即可看到php頁面


7.負載配置

[python] view plain copy
 在CODE上查看代碼片派生到我的代碼片
  1. upstream site{  
  2.         server 172.16.170.138;  
  3.         server 172.16.170.139;  
  4. }  
  5. server {  
  6.     listen       80;  
  7.     server_name  localhost;  
  8.   
  9.     #charset koi8-r;  
  10.     #access_log  /var/log/nginx/log/host.access.log  main;  
  11.   
  12.     location / {  
  13.         root   /usr/share/nginx/html;  
  14.         index  index.html index.htm;  
  15.         proxy_pass http://site;  
  16.     }  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章