首页 > 代码库 > linux 下安装 nginx

linux 下安装 nginx

 

安装nginx版本为1.7.5

一。下载nginx

官方地址:http://www.nginx.org/

下载地址:http://nginx.org/download/

Nginx官网提供了三个类型的版本

  1. Mainline version:Mainline 是 Nginx 目前主力在做的版本,可以说是开发版
  2. Stable version:最新稳定版,生产环境上建议使用的版本
  3. Legacy versions:遗留的老版本的稳定版

选择nginx-1.7.5

  将该下载包拷贝到/alidata/tools/下(随意了,找个地方就好,我的/alidata 是挂载进来的大盘,所以我习惯放这里)

cd /alidata/tools/wget -c http://nginx.org/download/nginx-1.7.5.tar.gz

 

二。安装

tar zxvf nginx-1.7.5.tar.gz cd nginx-1.7.5

按照一些网络资料的介绍,执行如下命令即可完成安装

./configuremakemake install

  设置一下配置信息 ./configure --prefix=/alidata/server/nginx-1.7.5 ,或者不执行此步,直接默认配置

但在实际安装过程中会,执行./configure时,根据系统的配置不同会有不同的错误提示,这里不罗嗦了,安装nginx需要安装openssl和 pcre,

  一般而言 OpenSSL 一般机子自己已经安装过了,下面我们看看pcre 的安装

下载pcre:http://sourceforge.net/projects/pcre/files/ ,选择pcre-8.35.tar.gz,拷贝到/alidata/tools/下并解压

下载OpenSSL :http://www.openssl.org/source/ ,选择openssl-1.0.1i.tar.gz,拷贝到/alidata/tools/下并解压

 

接着我们安装nginx,

cd /alidata/tools/nginx-1.7.5./configure --prefix=/alidata/server/nginx-1.7.5 --with-pcre=/alidata/tools/pcre-8.35 --with-http_ssl_module --with-openssl=/usr/bin/openssl

 

注意: 这里的 OpenSSL pcre 都必须是源码, 不能是编译后的路径

ok,nginx安装完成。

  启动 nginx:

/alidata/server/nginx-1.7.5/sbin/nginx -c /alidata/server/nginx-1.7.5/conf/nginx.conf

 

 

接着访问这台机器的80的端口,如果请求成功,则说明配置成功

 

为了操作方便,可以自己写一个nginx命令脚本,放到/etc/init.d下,并赋予其执行权限即可,详见附件,执行方法如下:

启动:service nginx start

停止:service nginx stop

重启:service nginx reconfigure

查看状态:service nginx status

 

 

 

 

 

 

 

debug 1:

[root@iZ23lt92evyZ ~]# cd /alidata/server/[root@iZ23lt92evyZ server]# wget -c http://nginx.org/download/nginx-1.7.5.tar.gz--2014-10-04 19:19:36--  http://nginx.org/download/nginx-1.7.5.tar.gzResolving nginx.org... 206.251.255.63Connecting to nginx.org|206.251.255.63|:80... connected.HTTP request sent, awaiting response... 200 OKLength: 817599 (798K) [application/octet-stream]Saving to: 鈥渘ginx-1.7.5.tar.gz鈥100%[======================================>] 817,599      195K/s   in 4.2s    2014-10-04 19:19:41 (190 KB/s) - 鈥渘ginx-1.7.5.tar.gz鈥saved [817599/817599][root@iZ23lt92evyZ server]# 

 

 

debug 2:

[root@iZ23lt92evyZ nginx-1.7.5]# ./configure --prefix=/alidata/server/nginx-1.7.5 --with-pcre=/alidata/tools/pcre-8.35 --with-http_ssl_module --with-openssl=/alidata/tools/openssl-1.0.1ichecking for OS + Linux 2.6.32-431.20.3.el6.x86_64 x86_64checking for C compiler ... found + using GNU C compiler + gcc version: 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC) checking for gcc -pipe switch ... foundchecking for gcc builtin atomic operations ... foundchecking for C99 variadic macros ... foundchecking for gcc variadic macros ... foundchecking for unistd.h ... foundchecking for inttypes.h ... foundchecking for limits.h ... foundchecking for sys/filio.h ... not foundchecking for sys/param.h ... foundchecking for sys/mount.h ... foundchecking for sys/statvfs.h ... foundchecking for crypt.h ... foundchecking for Linux specific featureschecking for epoll ... foundchecking for EPOLLRDHUP ... foundchecking for O_PATH ... not foundchecking for sendfile() ... foundchecking for sendfile64() ... foundchecking for sys/prctl.h ... foundchecking for prctl(PR_SET_DUMPABLE) ... foundchecking for sched_setaffinity() ... foundchecking for crypt_r() ... foundchecking for sys/vfs.h ... foundchecking for nobody group ... foundchecking for poll() ... foundchecking for /dev/poll ... not foundchecking for kqueue ... not foundchecking for crypt() ... not foundchecking for crypt() in libcrypt ... foundchecking for F_READAHEAD ... not foundchecking for posix_fadvise() ... foundchecking for O_DIRECT ... foundchecking for F_NOCACHE ... not foundchecking for directio() ... not foundchecking for statfs() ... foundchecking for statvfs() ... foundchecking for dlopen() ... not foundchecking for dlopen() in libdl ... foundchecking for sched_yield() ... foundchecking for SO_SETFIB ... not foundchecking for SO_ACCEPTFILTER ... not foundchecking for TCP_DEFER_ACCEPT ... foundchecking for TCP_KEEPIDLE ... foundchecking for TCP_FASTOPEN ... not foundchecking for TCP_INFO ... foundchecking for accept4() ... foundchecking for int size ... 4 byteschecking for long size ... 8 byteschecking for long long size ... 8 byteschecking for void * size ... 8 byteschecking for uint64_t ... foundchecking for sig_atomic_t ... foundchecking for sig_atomic_t size ... 4 byteschecking for socklen_t ... foundchecking for in_addr_t ... foundchecking for in_port_t ... foundchecking for rlim_t ... foundchecking for uintptr_t ... uintptr_t foundchecking for system byte ordering ... little endianchecking for size_t size ... 8 byteschecking for off_t size ... 8 byteschecking for time_t size ... 8 byteschecking for setproctitle() ... not foundchecking for pread() ... foundchecking for pwrite() ... foundchecking for sys_nerr ... foundchecking for localtime_r() ... foundchecking for posix_memalign() ... foundchecking for memalign() ... foundchecking for mmap(MAP_ANON|MAP_SHARED) ... foundchecking for mmap("/dev/zero", MAP_SHARED) ... foundchecking for System V shared memory ... foundchecking for POSIX semaphores ... not foundchecking for POSIX semaphores in libpthread ... foundchecking for struct msghdr.msg_control ... foundchecking for ioctl(FIONBIO) ... foundchecking for struct tm.tm_gmtoff ... foundchecking for struct dirent.d_namlen ... not foundchecking for struct dirent.d_type ... foundchecking for sysconf(_SC_NPROCESSORS_ONLN) ... foundchecking for openat(), fstatat() ... foundchecking for getaddrinfo() ... foundchecking for zlib library ... foundcreating objs/MakefileConfiguration summary  + using PCRE library: /alidata/tools/pcre-8.35  + using OpenSSL library: /alidata/tools/openssl-1.0.1i  + md5: using OpenSSL library  + sha1: using OpenSSL library  + using system zlib library  nginx path prefix: "/alidata/server/nginx-1.7.5"  nginx binary file: "/alidata/server/nginx-1.7.5/sbin/nginx"  nginx configuration prefix: "/alidata/server/nginx-1.7.5/conf"  nginx configuration file: "/alidata/server/nginx-1.7.5/conf/nginx.conf"  nginx pid file: "/alidata/server/nginx-1.7.5/logs/nginx.pid"  nginx error log file: "/alidata/server/nginx-1.7.5/logs/error.log"  nginx http access log file: "/alidata/server/nginx-1.7.5/logs/access.log"  nginx http client request body temporary files: "client_body_temp"  nginx http proxy temporary files: "proxy_temp"  nginx http fastcgi temporary files: "fastcgi_temp"  nginx http uwsgi temporary files: "uwsgi_temp"  nginx http scgi temporary files: "scgi_temp"

 

linux 下安装 nginx