分享好友 系统运维首页 频道列表

服务器 CentOS上yum安装Nginx服务

Nginx教程  2023-02-10 02:110

 一、更改yum源为网易的源加快速度

vi /etc/yum.repos.d/CentOS-Base.repo
更改内容如下

# CentOS-Base.repo
#
# This file uses a new mirrorlist system developed by Lance Davis for CentOS.
# The mirror system uses the connecting IP address of the client and the


# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

#released updates
[updates]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
baseurl=http://mirrors.163.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

#packages used/produced in the build but not released
[addons]
name=CentOS-$releasever - Addons
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=addons
#baseurl=http://mirror.centos.org/centos/$releasever/addons/$basearch/
baseurl=http://mirrors.163.com/centos/$releasever/addons/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
baseurl=http://mirrors.163.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
baseurl=http://mirrors.163.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5


二、update yum

yum -y update

三、利用CentOS Linux系统自带的yum命令安装、升级所需的程序库

LANG=C
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers

四、安装php和mysql

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

五、安装nginx
由于centos没有默认的nginx软件包,需要启用REHL的附件包

rpm -Uvh http://download.Fedora.RedHat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm
yum -y install nginx

设置开机启动

chkconfig nginx on

六、安装spawn-fcgi来运行php-cgi


yum install spawn-fcgi

七、下载spawn-fcgi 的启动脚本

wget http://bash.cyberciti.biz/dl/419.sh.zip
unzip 419.sh.zip
mv 419.sh /etc/init.d/php_cgi
chmod +x /etc/init.d/php_cgi

启动php_cgi

/etc/init.d/php_cgi start

查看进程

netstat -tulpn | grep :9000

若出现如下代表一切正常

tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 4352/php-cgi

八、配置nginx(详细配置见nginx.conf详细说明)

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;
include fastcgi_params;
}

九、查看phpinfo
编写脚本

phpinfo();

十、安装phpmyadmin
修改/var/lib/php/session的权限和nginx和php_cgi一致

chown -R www.www /var/lib/php/session

详情:http://www.myhack58.com/Article/sort099/sort0102/2011/29472.htm或者http://ninghao.net/blog/1368或者http://blog.sina.com.cn/s/blog_5fd841bf0101mwfz.html或者http://jingyan.baidu.com/article/5d368d1eed38ac3f60c05791.html?qq-pf-to=pcqq.c2c

查看更多关于【Nginx教程】的文章

展开全文
相关推荐
反对 0
举报 0
评论 0
图文资讯
热门推荐
优选好物
更多热点专题
更多推荐文章
Nginx端口占用问题
错误信息:nginx: [emerg] listen() to 0.0.0.0:80, backlog 511 failed (98: Address already in use)主要是端口被占用,通过如下命令,可以查看该端口被那个应用占用:sudo netstat -ntpl 然后kill -9 PID将其杀死关闭即可解决

0评论2023-02-13565

Linux使用nginx反向代理。可实现域名指向特定端口
在配置80指向域名的时候出现端口占用,使用kill -9无法杀死端口,应使用下面的命令来杀死进程killall -9 nginx(使用完本命令需要再把配置过的配置文件重新启动。命令写在了PS下面)后在root权限下的nginx的sbin下使用./nginx -t(命令重启nginx并检查是否有语

0评论2023-02-13636

装tomcat和nginx心得
开机启动tomcat1:在/etc/rc.d/init.d目录下生成一个文件tomcat80802:在文件里添加如下内#!/bin/bash#2345 linux运行级别#10开机启动优先级,数值越大越排在前面,最大值100#90关机优先级#chkconfig:2345 10 90#description: tomcat8080 start....start(){ec

0评论2023-02-13333

nginx 之 proxy_pass的使用
使用注意事项proxy_pass在nginx中作代理转发使用。如果在proxy_pass后面的url加/,表示绝对根路径;如果没有/,表示相对路径,把匹配的路径部分也给代理走。假设下面四种情况分别用 http://192.168.1.1/proxy/test.html 进行访问。第一种:location /proxy/

0评论2023-02-13675

用Nginx代理请求,处理前后端跨域 用nginx代理请求,处理前后端跨域文件
  自从前端spa框架出现后,都是前后端分离开发了。我们在开发的时候难免会遇到跨域的问题。跨域这种问题解决的方法基本都是在服务端实现的。以java为例,我知道的有3种方法处理跨域:  1.使用 @CrossOrigin 注解对每一个接口进行跨域处理,缺点是比较麻烦

0评论2023-02-13771

手动上传图片到nginx下可访问,程序上传后访问图片报403
1. 首先查看文件权限2. 初步确定是服务器权限问题2.1 解决方案一:更改文件权限2.2 解决方案二:修改nginx运行用户 1. 首先查看文件权限#指令如下ls -l2. 初步确定是服务器权限问题403 forbidden错误是禁止读取访问,也就是说服务器理解了请求,但是不允许访问

0评论2023-02-13745

check nginx配置文件错误:[emerg]: getpwnam(“nginx”) failed
 1、错误提示:[root@server include]# /application/nginx/sbin/nginx -t -c /applications/nginx/nginx/nginx.confnginx: [emerg] getpwnam("nginx") failed in /applications/nginx/nginx/nginx.conf:2nginx: configuration file /application/nginx/ngin

0评论2023-02-13620

Nginx 499的问题 PHP 异步 HTTP 与 NGINX 499
PHP 异步 HTTP在 PHP 代码中提交异步 HTTP 请求比较常用的方式是通过 fsockopen/fwrite/fclose 来实现,请参考如下代码。function post($host, $path, $port, $data) {$post = http_build_query($data);$len = strlen($post);$fp = fsockopen($host, $port,

0评论2023-02-13458

nginx FastCGI模块(FastCGI)配置
http://www.howtocn.org/nginx:nginx%E6%A8%A1%E5%9D%97%E5%8F%82%E8%80%83%E6%89%8B%E5%86%8C%E4%B8%AD%E6%96%87%E7%89%88:standardhttpmodules:fastcginginx官方文档:http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html 摘要这个模块允许nginx

0评论2023-02-10486

nginx+tomcat反向代理下使用tomcat-redis-session-manager进行session共享中值得注意的一个问题
公司目前项目使用nginx反向代理+多个tomcat进行负载均衡,之前使用ip_hash策略进行session控制。近期有考虑不再使用ip_hash策略,所以需要进行session共享。根据项目实际情况,拟考虑使用开发配置比较简单,应用比较广泛的tomcat-redis-session-manager方式进

0评论2023-02-10303

更多推荐