Ubuntu中ngnix安装方法

搞了半天的Ubuntu版的linux系统,看着别人各种装法,实则自己没搞清楚linux版本的一些东西。
CentOS(Community ENTerprise Operating System)是Linux发行版之一,它是来自于Red Hat Enterprise Linux依照开放源代码规定释出的源代码所编译而成。由于出自同样的源代码,因此有些要求高度稳定性的服务器以CentOS替代商业版的Red Hat Enterprise Linux使用。
  
  Ubuntu是一个以桌面应用为主的Linux操作系统,其名称来自非洲南部祖鲁语或豪萨语的“ubuntu”一词(译为吾帮托或乌班图),意思是“人性”、“我的存在是因为大家的存在”,是非洲传统的一种价值观,类似华人社会的“仁爱”思想。Ubuntu基于Debian发行版和GNOME桌面环境,与Debian的不同在于它每6个月会发布一个新版本。Ubuntu的目标在于为一般用户提供一个最新的、同时又相当稳定的主要由自由软件构建而成的操作系统。Ubuntu具有庞大的社区力量,用户可以方便地从社区获得帮助。
  
  两者同为目前版本中个人和小团队常用的服务级操作系统,在线提供的软件库中可以很方便的安装到很多开源的软件及库。 两者都使用bash作为基础shell,所以在很多基础命令上,ubuntu与centos的差别不是很明显,而ubuntu在桌面界面上要做的更为出色,很多人如果是从兴趣出发而学习linux的首选一般都是ubuntu,毕竟很多人还是很习惯在桌面图形下操作的。Centos与Ubuntu的使用习惯和命令上还是有很多的不同,下面简单列举一下:
  
  1.centos中新建的非root用户是没有sudo的权限的,如果需要使用sudo权限必须在/etc/sudoers 中加入账户和权限,所以切换到root账号的时候只需要输入:su,加入root账号的密码即可。
  在Ubuntu中,一般使用sudo+命令,如果是第一次使用会提示输入当前用户的密码(而不是root的密码)
  2.在线安装软件中,centos使用的是yum命令,而ubuntu中使用的是apt-get命令。除此之外yum中还有一个从软件源中搜索摸个软件的方法:yum search +软件名
  3.centos是来自于redhat,所以centos支持rpm格式的安装,而ubuntu显然是不支持的。
  4.毕竟是不同的公司做的不同的发行版,很多配置文件的位置和默认的文件路径都有很大区别,这个需要使用过程中慢慢体会了。












看了很多ngnix安装方法,这个算是顺畅的安装成功了,所以记下来,原博客地址http://www.cnblogs.com/piscesLoveCc/p/5794926.html

Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器。 Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,第一个公开版本0.1.0发布于2004年10月4日。其将源代码以类BSD许可证的形式发布,因它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名。

安装Nginx依赖库

安装gcc g++的依赖库

ubuntu平台可以使用如下命令。

1
2
apt-get install build-essential
apt-get install libtool

centeros平台可以使用如下命令。

1
2
3
4
5
6
centos平台编译环境使用如下指令
安装make:
yum -y install gcc automake autoconf libtool make
 
安装g++:
yum install gcc gcc-c++  

安装 pcre依赖库(http://www.pcre.org/

1
2
sudo apt-get update
sudo apt-get install libpcre3 libpcre3-dev

安装 zlib依赖库(http://www.zlib.net

1
apt-get install zlib1g-dev

安装 ssl依赖库

1
apt-get install openssl

安装Nginx(http://nginx.org

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#下载最新版本:
wget http://nginx.org/download/nginx-1.11.3.tar.gz  #找好当前最新版本号
#解压:
tar -zxvf nginx-1.11.3.tar.gz
#进入解压目录:
cd nginx-1.11.3
#配置:
./configure --prefix=/usr/local/nginx 
#编辑nginx:
make
注意:这里可能会报错,提示“pcre.h No such file or directory”,具体详见:http://stackoverflow.com/questions/22555561/error-building-fatal-error-pcre-h-no-such-file-or-directory
需要安装 libpcre3-dev,命令为:sudo apt-get install libpcre3-dev
#安装nginx:
sudo make install
#启动nginx:
sudo /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
注意:-c 指定配置文件的路径,不加的话,nginx会自动加载默认路径的配置文件,可以通过 -h查看帮助命令。
#查看nginx进程:
ps -ef|grep nginx

Nginx常用命令

启动 Nginx

1
2
3
/usr/local/nginx/sbin/nginx
 
./sbin/nginx 

停止 Nginx

1
2
3
./sbin/nginx -s stop
 
./sbin/nginx -s quit

-s都是采用向 Nginx 发送信号的方式。

Nginx重新加载配置

1
./sbin/nginx -s reload

指定配置文件

1
./sbin/nginx -c /usr/local/nginx/conf/nginx.conf

-c表示configuration,指定配置文件

查看 Nginx 版本

有两种可以查看 Nginx 的版本信息的参数。第一种如下:

1
2
3
./sbin/nginx -v
 
nginx: nginx version: nginx/1.0.0

另一种显示的是详细的版本信息:

1
2
3
4
5
poechant@ubuntu:/usr/local/nginx$ ./sbin/nginx -V
nginx: nginx version: nginx/1.0.0
nginx: built  by  gcc 4.3.3 (Ubuntu 4.3.3-5ubuntu4)
nginx: TLS SNI support enabled
nginx: configure arguments: --with-http_ssl_module --with-openssl=/home/luming/openssl-1.0.0d/

检查配置文件是否正确

1
2
3
4
5
poechant@ubuntu:/usr/local/nginx$ ./sbin/nginx -t
nginx: [alert] could not open error log file: open()  "/usr/local/nginx/logs/error.log"  failed (13: Permission denied)
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax  is  ok
2012/01/09 16:45:09 [emerg] 23898#0: open()  "/usr/local/nginx/logs/nginx.pid"  failed (13: Permission denied)
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed

如果出现如上的提示信息,表示没有访问错误日志文件和进程,可以sudo(super user do)一下:

1
2
3
poerchant@ubuntu:/usr/local/nginx$ sudo ./sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax  is  ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test  is  successful

如果显示如上,则表示配置文件正确。否则,会有相关提示。

显示帮助信息

1
poechant@ubuntu:/user/local/nginx$ ./sbin/nginx -h

或者:

1
poechant@ubuntu:/user/local/nginx$ ./sbin/nginx -?

猜你喜欢

转载自blog.csdn.net/oyy_90/article/details/80325500
今日推荐