http://www.hebinghua.com/linux/28.html

安装nginx配到的坑比事情。

https://www.runoob.com/linux/nginx-install-setup.html

安装nginx非常详细的教程

-----------------------------------------------------------------------------------------------------------------

正文

1 安装编译工具库文件

yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel

这一步没有要求路径

2 安装PCRE

yum -y install gcc gcc-c++ zlib zlib-devel openssl openssl-devel pcre pcre-devel

可以一起yum install 也可以去下载好源码包 然后安装即可

wget http://nginx.org/download/nginx-1.6.2.tar.gz

然后解压  ./configure   make && make install

安装好了之后我们执行这个测试一下 pcre-config --version是否安装好了。

3 安装nginx

2.1 官方网站下载Nginx, 默认安装路径:/usr/local/nginx

进入 cd /usr/local/nginx

下载命令:

wget http://nginx.org/download/nginx-1.12.2.tar.gz

2.2解压

tar zxvf nginx-1.12.2.tar.gz

进入nginx源文件目录

cd nginx-1.12.2

2.3编译

默认https没有打开,需要添加 --with-http_ssl_module

执行命令./configure --with-http_ssl_module

2.4 安装Nginx 执行make && make install

2.5 启动Nginx

/usr/local/nginx/sbin/nginx

浏览器输入http://服务器ip:80

总结:这个地方没那么顺利的,会遇见坑逼,详细的后面看 坑逼打全集。

4 nginx配置

创建 Nginx 运行使用的用户 www:

# /usr/sbin/groupadd www
# /usr/sbin/useradd -g www www

配置nginx.conf ,将/usr/local/nginx/conf/nginx.conf替换为以下内容

[root@bogon conf]#  cat /usr/local/nginx/conf/nginx.confuser www www;
worker_processes 2; #设置值和CPU核心数一致
error_log /usr/local/webserver/nginx/logs/nginx_error.log crit; #日志位置和日志级别
pid /usr/local/webserver/nginx/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
events
{use epoll;worker_connections 65535;
}
http
{include mime.types;default_type application/octet-stream;log_format main  '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" $http_x_forwarded_for';#charset gb2312;server_names_hash_bucket_size 128;client_header_buffer_size 32k;large_client_header_buffers 4 32k;client_max_body_size 8m;sendfile on;tcp_nopush on;keepalive_timeout 60;tcp_nodelay on;fastcgi_connect_timeout 300;fastcgi_send_timeout 300;fastcgi_read_timeout 300;fastcgi_buffer_size 64k;fastcgi_buffers 4 64k;fastcgi_busy_buffers_size 128k;fastcgi_temp_file_write_size 128k;gzip on; gzip_min_length 1k;gzip_buffers 4 16k;gzip_http_version 1.0;gzip_comp_level 2;gzip_types text/plain application/x-javascript text/css application/xml;gzip_vary on;#limit_zone crawler $binary_remote_addr 10m;#下面是server虚拟主机的配置server{listen 80;#监听端口server_name localhost;#域名index index.html index.htm index.php;root /usr/local/webserver/nginx/html;#站点目录location ~ .*\.(php|php5)?${#fastcgi_pass unix:/tmp/php-cgi.sock;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;include fastcgi.conf;}location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico)${expires 30d;# access_log off;}location ~ .*\.(js|css)?${expires 15d;# access_log off;}access_log off;}}

检查配置文件nginx.conf的正确性命令:

/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload            # 重新载入配置文件
/usr/local/nginx/sbin/nginx -s reopen            # 重启 Nginx
/usr/local/n-inx/sbin/nginx -s stop              # 停止 Nginx

坑来了:

扩展模块,需要编译安装的nginx,版本自己选择(我的是1.14.0)

1.获取安装包

    wget http://nginx.org/download/nginx-1.14.1.tar.gzwget https://codeload.github.com/yaoweibin/nginx_upstream_check_module/zip/master

2.安装扩展依赖

    yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel

3.给nginx打个补丁(加入nginx+nginx_upstream_check_module)

1>.进入nginx-1.14目录(源码目录)

    patch -p1 < /usr/download/nginx_upstream_check_module-master/check_1.14.0+.patch

ps:我的两个包下载在/usr/download/,这个自定义 ;master加压后的文件为nginx_upstream_check_module-master 里面包含了多个补丁版本,根据自己的nginx版本选择

2>.新建一个nginx的安装目录,我的在/usr/local/nginx-1.14.1,然后还在nginx的源码目录中执行

    ./configure --prefix=/usr/local/nginx-1.14.1 --add-module=/usr/download/nginx_upstream_check_module-master/

正常现象:

    Configuration summary+ using system PCRE library+ OpenSSL library is not used+ using system zlib librarynginx path prefix: "/usr/local/nginx-1.14.1"nginx binary file: "/usr/local/nginx-1.14.1/sbin/nginx"nginx modules path: "/usr/local/nginx-1.14.1/modules"nginx configuration prefix: "/usr/local/nginx-1.14.1/conf"nginx configuration file: "/usr/local/nginx-1.14.1/conf/nginx.conf"nginx pid file: "/usr/local/nginx-1.14.1/logs/nginx.pid"nginx error log file: "/usr/local/nginx-1.14.1/logs/error.log"nginx http access log file: "/usr/local/nginx-1.14.1/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"

大概率报错:

    [root@localhost nginx-1.14.1]# ./configure --prefix=/usr/local/nginx-1.14.1 --add-module=/usr/download/nginx_upstream_check_module-master/checking for OS+ Linux 4.18.0-80.el8.x86_64 x86_64checking for C compiler ... not found./configure: error: C compiler cc is not found

解决办法:

    yum -y install gcc gcc-c++ autoconf automake make

3>.编译 make

    make

大概率出现的报错:

    make[1]: 进入目录“/usr/download/nginx-1.14.1”cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I /usr/download/nginx_upstream_check_module-master/ -I objs \-o objs/src/os/unix/ngx_user.o \src/os/unix/ngx_user.csrc/os/unix/ngx_user.c: 在函数‘ngx_libc_crypt’中:src/os/unix/ngx_user.c:26:7: 错误:‘struct crypt_data’没有名为‘current_salt’的成员cd.current_salt[0] = ~salt[0];^make[1]: *** [objs/Makefile:788:objs/src/os/unix/ngx_user.o] 错误 1

解决办法: 打开 src/os/unix/ngx_user.c

    #ifdef __GLIBC__/* work around the glibc bug */cd.current_salt[0] = ~salt[0];     ##把这一行注释掉#endif

4>.编译安装

    make install

大概率报错:

        igned int (*)(struct <匿名> *)’} to ‘void (*)(ngx_http_script_engine_t *)’ {或称 ‘void (*)(struct <匿名> *)’} [-Werror=cast-function-type]code->code = (ngx_http_script_code_pt)^src/http/ngx_http_script.c: 在函数‘ngx_http_script_add_full_name_code’中:src/http/ngx_http_script.c:1296:18: 错误:cast between incompatible function types from ‘size_t (*)(ngx_http_script_engine_t *)’ {或称 ‘long unsigned int (*)(struct <匿名> *)’} to ‘void (*)(ngx_http_script_engine_t *)’ {或称 ‘void (*)(struct <匿名> *)’} [-Werror=cast-function-type]code->code = (ngx_http_script_code_pt) ngx_http_script_full_name_len_code;^cc1:所有的警告都被当作是错误make[1]: *** [objs/Makefile:893:objs/src/http/ngx_http_script.o] 错误 1make[1]: 离开目录“/usr/download/nginx-1.14.1”make: *** [Makefile:8:build] 错误 2

解决办法:打开  vim objs/Makefile  把 -Werrori删掉   (-Werror,它要求GCC将所有的警告当成错误进行处理)

5.>启动nginx

在刚刚自定义的nginx安装目录里有生成的文件,其中,启动文件在sbin里

直接启动:./sbin/nginx -s reload

有可能出现报错:

        root@localhost sbin]# ./nginx -s reloadnginx: [error] open() "/usr/local/nginx-1.14.1/logs/nginx.pid" failed (2: No such file or directory)

解决办法:

        [root@localhost sbin]# /usr/local/nginx-1.14.1/sbin/nginx -c /usr/local/nginx-1.14.1/conf/nginx.conf[root@localhost sbin]# cd ../logs/[root@localhost logs]# ll总用量 8-rw-r--r-- 1 root root   0 1月   7 15:11 access.log-rw-r--r-- 1 root root 593 1月   7 15:30 error.log-rw-r--r-- 1 root root   6 1月   7 15:33 nginx.pid

然后就可以正常启动了

4.nginx配置

打开nginx.conf配置文件添加  include /etc/vhost/*.conf  (个人习惯,引入一个配置文件)

然后根据在《nginx均衡负载》一文中跟均衡负载搭配使用。

5.检测可视化

在nginx的配置里加上一段

    location /nastatus {check_status;access_log off;}

ps:/nastatus 自定义一个路径

然后打开web访问这个地址 比如 http://192.168.5.165/nastatus

centos安装nginx教程相关推荐

  1. yum安装Nginx教程

    yum安装Nginx教程   安装CentOS 7:本人原创 更新yum yum update -y 下载Nginx 安装nginx源 rpm -ivh http://nginx.org/packag ...

  2. php5.3+for+linux,Centos 安装 nginx + php5.3

    Centos 安装 nginx + php5.3,点开查看详情. #查看系统版本信息cat /etc/issue uname -a#设置时区 rm -rf /etc/localtime ln -s / ...

  3. CentOS安装Redis教程

    CentOS安装Redis教程 从官网下载Redis:https://redis.io/download 进入下载文件夹,解压安装包到opt目录下:tar -zxvf redis-4.0.2.tar. ...

  4. Linux下安装nginx教程

    Linux下安装nginx教程 安装依赖包 #执行一下命令 安装4个依赖包 yum -y install gcc zlib zlib-devel pcre-devel openssl openssl- ...

  5. Ubuntu和Centos安装Tensorflow教程PyTorch

    更多请关注: https://github.com/chanhal https://www.zhihu.com/people/chanhal https://github.com/chanhal/co ...

  6. 苹果电脑mac安装nginx教程

    苹果电脑MAC安装nginx教程 使用homebrew安装,提醒需要翻墙,最后面介绍的源码安装方式不需要翻墙,只需要在墙内搞到源码即可,建议先确认一下自己能否翻墙,如果可以翻墙就用第一种方法,如果不能 ...

  7. 在centOS7中安装nginx教程

    在centOS7中安装nginx教程 在安装nginx之前,确保你的虚拟机能够联网! 安装nginx步骤: 一.安装好nginx所依赖的环境(gcc.PCRE.zlib.Open SSL). 二.安装 ...

  8. docker安装nginx教程

    Docker安装Nginx教程(小白教程) 1.查看可用的 Nginx 版本 Nginx 镜像库:Docker Hub . 我们还可以用 docker search nginx 命令来查看可用版本:  ...

  9. linux安装nginx教程

    linux安装nginx教程 安装依赖包 yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel 下载安装包 # 我是装 ...

最新文章

  1. 深入理解阿里分布式消息中间件
  2. Web服务器、Servlet和Servlet容器
  3. java aio为什么不稳定_为什么我不提倡在Java中使用static
  4. 深入理解spark两种调度模式:FIFO,FAIR模式
  5. 美团在Redis上踩过的一些坑-5.redis cluster遇到的一些问题
  6. jquery 监听td点击事件_安卓开发监听点击事件的一种方法
  7. 4.01~ios开发常用的宏
  8. 软件开发:到底谁还在传言软件巨头濒临死亡?
  9. JavaSE、JavaEE、JavaME之间的区别
  10. 安排,Java智慧农业物联网项目视频2020
  11. C#:合并EXCEL文件工作表列
  12. MyBatis:万能Map和模糊查询(狂神)
  13. 为什么别人不回你的微信?说说如何正确的提问
  14. 班章管家:为什么出资会亏钱?在出资中“勤勉”并不管用
  15. 计算机创建管理员用户名和密码,如何给电脑设置管理员登录密码?
  16. 给百度地图每个市添加颜色
  17. 是时候展示给大家这5款压箱底的软件了
  18. 中国移动敲定A股发行价,预计上市时市值将达到1.18万亿元
  19. android timer时间间隔,间隔计时器IntervalTimer
  20. 制作自己的多媒体个性相册(上篇)

热门文章

  1. leetcode 二分
  2. 关于和discuz!nt论坛的整合
  3. 毕业季!如何邮寄行李最划算?MATLAB教你选择性价比最高邮寄方式
  4. 第六天:结构型模式--修饰器模式
  5. 开关三极管使用细节若干问题
  6. Go IDE vscode (by quqi99)
  7. java8 stream 的list处理
  8. Python编程:为世界贡献你的轮子-pipy打包
  9. Python-12306模拟自动购票
  10. 【Python入门刷题】——NP10 牛牛最好的朋友们