yum安装nginx for RHEL/CentOS

建立RHEL / CentOS yum存储库,选择相应的nginx释放包从列表:
RHEL 6

rpm -ivh http://nginx.org/packages/rhel/6/noarch/RPMS/nginx-release-rhel-6-0.el6.ngx.noarch.rpm

CentOS 6

rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm

查看nginx

yum info nginx

安装nginx

yum -y install nginx

启动

service nginx start

加入服务

chkconfig nginx on

##############安装php+mysql########################

yum -y install php mysql mysql-server mysql-devel php-mysql php-cgi php-mbstring php-gd php-fastcgi
chkconfig mysqld on

通过以上命令,lnmp环境就此安装完毕。上传网站文件

安装后,NGINX的网站目录位于:
/usr/share/nginx/html
NGINX的配置文件位于:
/etc/nginx/nginx.conf

nginx -t              测试配置文件
nginx -v             查看相关版本

二、配置虚拟主机
在APACHE上配置虚拟主机。想来各位都有一定的体验。那如何在NGINX中实现呢?

[root@nginx-freetds html]# vi /etc/nginx/nginx.conf

把下面这段加在最后一个}之前:

server {
listen       80;
server_name  nginx.onexin.com;
location / {
root   /usr/share/nginx/html/bbs;
index  index.php index.html;
}
error_page  404              /404.html;
location = /404.html {
root   /usr/share/nginx/html;
}
error_page   500 502 503 504  /50x.html;
location = /50x.html {
root   /usr/share/nginx/html;
}
location ~ \.php$ {
root           html/bbs/;
fastcgi_pass   127.0.0.1:9000;
fastcgi_index  index.php;
include        /etc/nginx/fastcgi.conf;
}
}

Leave a Reply