当前位置: 主页 > 知识大全 >

CentOS服务器环境配置方法介绍

时间:2015-10-22 18:05    来源:青青草原WiFi    阅读:

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安装配置成功。

CentOS服务器环境配置方法介绍

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文件的内容如下:

echo "";

echo "hello world";

?>

2. 在浏览器中,通过CentOS云服务器公网IP查看环境配置是否成功。

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

CentOS服务器环境配置方法介绍

(注:本文来自互联网,不代表本站的观点和立场,如侵犯了您的权益,请您告知,邮件@gmail.com联系我们删除,谢谢。)

标签: CentOS服务器 CentOS环境配置

最新文章

·介绍国内免费网盘直链,免费CDN加速

·《不思议迷宫》手游皮特技能什么意思

·《阴阳师》式神总决选怎么投票

·《王者荣耀》新版达摩怎么出装

·《不思议迷宫》创世之门平民怎么打通关

·《王者荣耀》S6射手怎么出装比较好

·《王者荣耀》S6哪些刺客英雄好上分

·《不思议迷宫》创世之门100层奖励汇总

热点文章

·笔记本无线连接wifi连接成功,却上不了

·4种方法解决蓝牙与WiFi信号干扰的问题

·苹果电脑MacBook连不上WiFi怎么办?

·VMWare虚拟机提示:锁定文件失败,打不

·电脑无法识别USB无线网卡怎么办?

·开机去掉“选择要启动的操作系统,或按

·华为荣耀3C畅玩版(Hol-T00移动3G)手机

·Win7文字显示乱码,修复电脑中文乱码的