百分百源码网-让建站变得如此简单! 登录 注册 签到领金币!

主页 | 如何升级VIP | TAG标签

当前位置: 主页>网站教程>服务器> 腾迅CentOS云服务器nginx+php环境配置
分享文章到:

腾迅CentOS云服务器nginx+php环境配置

发布时间:01/15 来源: 浏览: 关键词:
nginx+php环境在linux系统中都需要安装配置了,我们在这里为各位介绍腾迅CentOS云服务器nginx+php环境配置,具体的细节如下所示。

1. 配置nginx

1. 启动nginx服务。
命令如下:
[root@VM_185_51 /]# service nginx restart

2. 测试nginx服务是否正常运行。
如果最后显示:`index.html' saved ,说明nginx服务正常。
[root@VM_185_51 /]# wget http://127.0.0.1
--2013-02-20 17:07:26-- http://127.0.0.1/
Connecting to 127.0.0.1:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 151 [text/html]
Saving to: `index.html'
100%[==========================================================================================>] 151 --.-K/s in 0s
2013-02-20 17:07:26 (37.9 MB/s) - `index.html' saved [151/151]

3. 在浏览器中,通过CentOS云服务器公网IP查看nginx服务是否正常运行。
如果显示如下,说明nginx安装配置成功。

Q_lnmp_1.png

2. 配置PHP

1. 启动php-fpm。
[root@VM_185_51 /]# service php-fpm start

2. 修改php-fpm和nginx的配置,实现nginx和php联动。
(1)查看php-fpm默认配置。
[root@VM_185_51 /]# cat /etc/php-fpm.d/www.conf |grep -i 'listen ='
listen = 127.0.0.1:9000
(2)php-fpm的默认配置的监听端口为9000,现在只用修改配置,将php解析的请求转发到127.0.0.0:9000处理即可。
修改nginx配置,修改命令如下:
[root@VM_185_51 /]# vim /etc/nginx/conf.d/default.conf

修改完成后实际配置如下,红色文字为修改过的部分:

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;
  }
  # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  #
  #location ~ \.php$ {
  #    proxy_pass   http://127.0.0.1;
  #}
  # 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;
  }
  # deny access to .htaccess files, if Apache's document root
  # concurs with nginx's one
  #
  #location ~ /\.ht {
  #    deny  all;
  #}
}
修改完成后,按“Esc”键,输入“:wq”,保存文件并返回。
通过下面的命令,查看配置是否正确:
[root@VM_185_51 /]# cat /etc/nginx/conf.d/default.conf

3. 配置生效

重启nginx,使配置生效。
命令如下:
[root@VM_185_51 /]# service nginx restart
Stopping nginx: [ OK ]
Starting nginx: [ OK ]

4. 环境配置验证

1. 在web目录下创建index.php。
命令如下:
[root@VM_185_51 /]# vim /usr/share/nginx/html/index.php
index.php文件的内容如下:
<?php
echo "<title>Test Page</title>";
echo "hello world";
?>
2. 在浏览器中,通过CentOS云服务器公网IP查看环境配置是否成功。

Q_lnmp_2.png

如果页面可以显示“hello world”,说明配置成功。

打赏

打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

百分百源码网 建议打赏1~10元,土豪随意,感谢您的阅读!

共有4人阅读,期待你的评论!发表评论
昵称: 网址: 验证码: 点击我更换图片
最新评论

本文标签

广告赞助

能出一分力是一分吧!

订阅获得更多模板

本文标签

广告赞助

订阅获得更多模板