Nginx配置:
在/etc/yum.repos.d/目录下创建一个源配置文件nginx.repo:
cd /etc/yum.repos.d/ -> gedit nginx.repo
填写如下内容:
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/6/$basearch/
gpgcheck=0
enabled=1
保存,则会产生一个/etc/yum.repos.d/nginx.repo文件。
下载:yum install nginx -y
启动服务:service nginx start
浏览器输入:localhost -> 看到Nginx欢迎页面”Welcome to nginx”
如果还无法访问,则需配置一下Linux防火墙。
gedit /etc/sysconfig/iptables
-A INPUT -m state –state NEW -m tcp -p tcp –dport 加入端口号 -j ACCEPT
加强防火墙设置:setenforce
重启执行:service iptables restart
支持php:
扩展:yum install php-fpm
重启:service php-fpm start
更改配置:gedit /etc/nginx/conf.d/default.conf
找到这段配置代码:
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
去掉注释,改为
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name; (这里可以绝对路径也可以写相对路径:$document_root)
include fastcgi_params;
}
测试环境:
添加文件:touch /usr/share/nginx/html/info.php
修改文件内容:gedit /usr/share/nginx/html/info.php
写入代码:
重启服务:service nginx restart
service php-fpm restart
浏览器输入:localhost/info.php
支持mysql
开启mysql服务:service mysqld start
测试环境:
添加文件:touch /usr/share/nginx/html/mysql.php
修改文件内容:gedit /usr/share/nginx/html/mysql.php
写入代码:
浏览器输入:localhost/mysql.php