资讯专栏INFORMATION COLUMN

Centos7下安装nginx源码包超详细教程(小白篇)!

caoym / 3695人阅读

摘要:环境新系统首先使用命令下载的源码包,并解压为了安全添加用户和组,以便以后以用户的身份运行程序,而非开始执行脚本,进行编译前的配置配置脚本有很多的参数,这里就只列出几个常用的安装目录获取更多配置使用命令提示编译器未找到。

###环境:CentOS Linux release 7.5.1804 (Core) 新系统

0.首先使用wget命令下载nginx的源码包,并解压

</>复制代码

  1. [root@localhost ~]# wget http://nginx.org/download/nginx-1.15.5.tar.gz
  2. --2018-11-06 16:59:08-- http://nginx.org/download/nginx-1.15.5.tar.gz
  3. Resolving nginx.org (nginx.org)... 206.251.255.63, 95.211.80.227, 2606:7100:1:69::3f, ...
  4. Connecting to nginx.org (nginx.org)|206.251.255.63|:80... connected.
  5. HTTP request sent, awaiting response... 200 OK
  6. Length: 1024791 (1001K) [application/octet-stream]
  7. Saving to: ‘nginx-1.15.5.tar.gz
  8. 100%[======================================================================================>] 1,024,791 245KB/s in 4.1s
  9. 2018-11-06 16:59:13 (245 KB/s) - ‘nginx-1.15.5.tar.gz’ saved [1024791/1024791]
  10. [root@localhost ~]# tar -xf nginx-1.15.5.tar.gz
  11. [root@localhost ~]# ls
  12. nginx-1.15.5 nginx-1.15.5.tar.gz
  13. [root@localhost ~]# cd nginx-1.15.5/
  14. [root@localhost nginx-1.15.5]# ls
  15. auto CHANGES CHANGES.ru conf configure contrib html LICENSE man README src

1.为了安全添加nginx用户和组,以便以后以nginx用户的身份运行nginx程序,而非root

</>复制代码

  1. [root@localhost nginx-1.15.5]# useradd nginx -s /sbin/nologin

2.开始执行configure脚本,进行编译前的配置 #configure配置脚本有很多的参数,这里就只列出几个常用的:--prefix:安装目录 --user -group. 获取更多配置使用 ./configure --help命令

</>复制代码

  1. [root@localhost nginx-1.15.5]# ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_ssl_module --with-stream
  2. checking for OS
  3. + Linux 3.10.0-862.el7.x86_64 x86_64
  4. checking for C compiler ... not found
  5. ./configure: error: C compiler cc is not found
  6. ###提示C编译器未找到。我们安装gcc编译器重新尝试
  7. [root@localhost nginx-1.15.5]# yum -y install gcc
  8. [root@localhost nginx-1.15.5]# ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_ssl_module --with-stream
  9. checking for PCRE library in /usr/local/ ... not found
  10. checking for PCRE library in /usr/include/pcre/ ... not found
  11. checking for PCRE library in /usr/pkg/ ... not found
  12. checking for PCRE library in /opt/local/ ... not found
  13. ./configure: error: the HTTP rewrite module requires the PCRE library.
  14. You can either disable the module by using --without-http_rewrite_module
  15. option, or install the PCRE library into the system, or build the PCRE library
  16. statically from the source with nginx by using --with-pcre= option.
  17. ###此时又提示HTTP重定向模块需要PCRE库,你可以使用--without-http_rewirte_module命令把这个默认安装的模块屏蔽掉,或者安装PCRE库文件,或者创建PCRE库使用--with-pcre选项来指定位置,这里我们选择安装库文件
  18. [root@localhost nginx-1.15.5]# yum -y install pcre-devel
  19. [root@localhost nginx-1.15.5]# ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_ssl_module --with-stream
  20. checking for OpenSSL library ... not found
  21. checking for OpenSSL library in /usr/local/ ... not found
  22. checking for OpenSSL library in /usr/pkg/ ... not found
  23. checking for OpenSSL library in /opt/local/ ... not found
  24. ./configure: error: SSL modules require the OpenSSL library.
  25. You can either do not enable the modules, or install the OpenSSL library
  26. into the system, or build the OpenSSL library statically from the source
  27. with nginx by using --with-openssl= option.
  28. ###又提示OpenSSL没有,没办法编译就是这么麻烦,继续装包吧
  29. [root@localhost nginx-1.15.5]# yum -y install openssl-devel
  30. [root@localhost nginx-1.15.5]# ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_ssl_module --with-stream
  31. Configuration summary
  32. + using system PCRE library
  33. + using system OpenSSL library
  34. + using system zlib library
  35. nginx path prefix: "/usr/local/nginx"
  36. nginx binary file: "/usr/local/nginx/sbin/nginx"
  37. nginx modules path: "/usr/local/nginx/modules"
  38. nginx configuration prefix: "/usr/local/nginx/conf"
  39. nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  40. nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  41. nginx error log file: "/usr/local/nginx/logs/error.log"
  42. nginx http access log file: "/usr/local/nginx/logs/access.log"
  43. nginx http client request body temporary files: "client_body_temp"
  44. nginx http proxy temporary files: "proxy_temp"
  45. nginx http fastcgi temporary files: "fastcgi_temp"
  46. nginx http uwsgi temporary files: "uwsgi_temp"
  47. nginx http scgi temporary files: "scgi_temp"
  48. ###此时配置成功,出现了配置信息

3.进行编译并复制文件到相应目录

</>复制代码

  1. [root@localhost nginx-1.15.5]# make && make install
  2. ###此时会出现一堆信息,无视就好,warningerror除外!
  3. [root@localhost ~]# ls /usr/local/nginx/
  4. conf html logs sbin
  5. ###nginx安装完成!!!

4.启动nginx进行访问测试

</>复制代码

  1. [root@localhost nginx]# ./sbin/nginx
  2. [root@localhost nginx]# netstat -nutlp | grep nginx
  3. tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 44202/nginx: master
  4. ###查看到nginx进程正在监听80端口即为成功,下面进行curl访问测试,web页面也可以,更直观
  5. [root@localhost nginx]# curl http://127.0.0.1
  6. Welcome to nginx!
  7. Welcome to nginx!

  8. If you see this page, the nginx web server is successfully installed and

  9. working. Further configuration is required.

  10. For online documentation and support please refer to

  11. nginx.org.
  12. Commercial support is available at
  13. nginx.com.

  14. Thank you for using nginx.

  15. ###看到welcome to nginx!即为成功。

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/40170.html

相关文章

  • Centos7安装nginx源码包超详细教程(小白)!

    摘要:环境新系统首先使用命令下载的源码包,并解压为了安全添加用户和组,以便以后以用户的身份运行程序,而非开始执行脚本,进行编译前的配置配置脚本有很多的参数,这里就只列出几个常用的安装目录获取更多配置使用命令提示编译器未找到。 ###环境:CentOS Linux release 7.5.1804 (Core) 新系统 0.首先使用wget命令下载nginx的源码包,并解压 [root@...

    caikeal 评论0 收藏0
  • 服务器小白的我,是如何成功将 node+mongodb 项目部署在服务器上并进行性能优化的

    摘要:前言本文讲解的是做为前端开发人员,对服务器的了解还是小白的我,是如何一步步将项目部署在阿里云的服务器上,并进行性能优化,达到页面秒内看到,秒内看到首屏内容的。搭建的项目是采用了主流的前后端分离思想的,这里只讲服务器环境搭建与性能优化。 showImg(https://segmentfault.com/img/remote/1460000017143281); 前言 本文讲解的是:做为前...

    zsy888 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<