侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

Linux下安装配置nginx详解

linux  /  管理员 发布于 7年前   145

一、Linux下安装配置nginx

第一次安装nginx,中间出现的问题一步步解决。

用到的工具secureCRT,连接并登录服务器。

1.1 rz命令,会弹出会话框,选择要上传的nginx压缩包。

#rz 

1.2 解压

[root@vw010001135067 ~]# cd /usr/local/[root@vw010001135067 local]# tar -zvxf nginx-1.10.2.tar.gz

1.3 进入nginx文件夹,执行./configure命令

[root@vw010001135067 local]# cd nginx-1.10.2[root@vw010001135067 nginx-1.10.2]# ./configure

报错如下:

checking for OS + Linux 2.6.32-431.el6.x86_64 x86_64checking for C compiler ... not found./configure: error: C compiler cc is not found

出现这个错误。那么就是gcc 包没有安装。

1.3.1 安装gcc

查看gcc

[root@vw010001135067 nginx-1.10.2]# whereis gccgcc:

安装gcc

[root@vw010001135067 nginx-1.10.2]# yum -y install gcc

安装成功后再次查看

[root@vw010001135067 nginx-1.10.2]# whereis gccgcc: /usr/bin/gcc /usr/lib/gcc /usr/libexec/gcc /usr/share/man/man1/gcc.1.gz

gcc安装好了。

1.3.2 继续执行./configure

[root@vw010001135067 nginx-1.10.2]# ./configurechecking for OS + Linux 2.6.32-431.el6.x86_64 x86_64checking for C compiler ... found......checking for PCRE library ... not foundchecking for PCRE library in /usr/local/ ... not foundchecking for PCRE library in /usr/include/pcre/ ... not foundchecking for PCRE library in /usr/pkg/ ... not foundchecking for PCRE library in /opt/local/ ... not found./configure: error: the HTTP rewrite module requires the PCRE library.You can either disable the module by using --without-http_rewrite_moduleoption, or install the PCRE library into the system, or build the PCRE librarystatically from the source with nginx by using --with-pcre=<path> option.

出现如上错误。安装pcre-devel

[root@vw010001135067 nginx-1.10.2]# yum install pcre-devel

1.3.3 再次执行./configure

error: the HTTP gzip module requires the zlib library.You can either disable the module by using --without-http_gzip_moduleoption, or install the zlib library into the system, or build the zlib librarystatically from the source with nginx by using --with-zlib=<path> option.

如果有这个错误 那么执行

yum install zlib-devel

1.3.4 执行./configure后没有报错

[root@vw010001135067 nginx-1.10.2]# ./configurechecking for OS + Linux 2.6.32-431.el6.x86_64 x86_64checking for C compiler ... found + using GNU C compiler + gcc version: 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC) .......Configuration summary + using system PCRE library + OpenSSL library is not used + md5: using system crypto library + sha1: using system crypto library + using system zlib library nginx path prefix: "/usr/local/nginx" nginx binary file: "/usr/local/nginx/sbin/nginx" nginx modules path: "/usr/local/nginx/modules" nginx configuration prefix: "/usr/local/nginx/conf" nginx configuration file: "/usr/local/nginx/conf/nginx.conf" nginx pid file: "/usr/local/nginx/logs/nginx.pid" nginx error log file: "/usr/local/nginx/logs/error.log" nginx http access log file: "/usr/local/nginx/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"

1.4 如果你想使用openssl 功能,sha1 功能。 那么安装openssl ,sha1 吧

[root@vw010001135067 nginx-1.10.2]# yum install openssl openssl-devel [root@vw010001135067 nginx-1.10.2]# install perl-Digest-SHA1.x86_64

1.4.1 开启ssl 模块 执行./configure Cwith-http_ssl_module

[root@vw010001135067 nginx-1.10.2]# ./configure --with-http_ssl_module

1.4.2 启用“server+status”页,执行./configure Cwith-http_stub_status_module

[root@vw010001135067 nginx-1.10.2]# ./configure --with-http_stub_status_module

上面两个命令同时启动可以

复制代码 代码如下:
[root@vw010001135067 nginx-1.10.2]# ./configure --with-http_stub_status_module --with-http_ssl_module

1.5 上面configure就通过了

执行make 命令,执行make install 命令

[root@vw010001135067 nginx-1.10.2]# make[root@vw010001135067 nginx-1.10.2]# make install

至此,nginx 执行成功了

1.6 配置环境变量

在/etc/profile 中加入配置

打开配置文件

[root@vw010001135067 nginx-1.10.2]# vi /etc/profile

在配置文件中加入

#nginx configureexport NGINX_HOME=/usr/local/nginx-1.10.2export PATH=$PATH:$NGINX_HOME/sbin

我开始像上面填写,结果nginx -v的时候查找不到。注意到上面我的nginx_home配置的地址不对。先找到nginx的安装地址

[root@vw010001135067 nginx-1.10.2]# whereis nginxnginx: /usr/local/nginx

还真是地址写错了,把上面的改成

#nginx configureexport NGINX_HOME=/usr/local/nginxexport PATH=$PATH:$NGINX_HOME/sbin

编译完保存退出并执行

[root@vw010001135067 nginx-1.10.2]# source /etc/profile

使配置生效。

1.7 查看nginx版本

[root@vw010001135067 nginx]# nginx -vnginx version: nginx/1.10.2

整个过程成功了!

二、修改nginx.conf

2.1 启动nginx

我的nginx服务在http://10.1.135.67/,配置成功后,现在启动nginx

[root@vw010001135067 nginx]# cd /usr/local/nginx[root@vw010001135067 nginx]# nginx -c conf/nginx.conf

启动成功,在浏览器打开http://10.1.135.67/,默认端口号80.

如上图,nginx已经正常工作了。

2.2 配置tomcat服务

现在我的tomcat服务在10.1.29.15,需要通过nginx转发。那么打开nginx.conf,修改配置文件。如下,添加:

#user nobody;worker_processes 1;#error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;#pid  logs/nginx.pid;events { worker_connections 1024;#最大连接数,默认为512 accept_mutex on; #设置网路连接序列化,防止惊群现象发生,默认为on multi_accept on; #设置一个进程是否同时接受多个网络连接,默认为off #use epoll;  #事件驱动模型,select|poll|kqueue|epoll|resig|/dev/poll|eventport }http { #文件扩展名与文件类型映射表 include  mime.types; #默认文件类型,默认为text/plain  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"';  #combined为日志格式的默认值 access_log logs/access.log main; #允许sendfile方式传输文件,默认为off,可以在http块,server块,location块 sendfile  on; sendfile_max_chunk 100k; #每个进程每次调用传输数量不能大于设定的值,默认为0,即不设上限。 #tcp_nopush  on; #连接超时时间,默认为75s,可以在http,server,location块。 keepalive_timeout 65; #gzip on; upstream upload {  server 10.1.29.15:8080; } error_page 404 https://www.baidu.com; #错误页 server {  keepalive_requests 120; #单连接请求上限次数。  listen  80; #监听端口  server_name localhost; #监听地址   #charset koi8-r;  #access_log logs/host.access.log main;  location ~ ^.*?/upload/[^/]*?$ {   proxy_connect_timeout 15;   proxy_send_timeout 15;   proxy_read_timeout 15;   proxy_set_header Host $host;   proxy_set_header X-Real-IP $remote_addr;   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;   proxy_set_header Connection "";   proxy_pass http://upload; #请求转向upload 定义的服务器列表   client_max_body_size 1024m;}  }}

配置好后,保存配置文件,并且重启nginx

[root@vw010001135067 nginx]# nginx -s reload

在浏览器调用upload项目是否成功

如图能正确访问项目,配置成功!

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。


  • 上一条:
    Linux INotif机制详解及实例代码
    下一条:
    CentOS 离线安装gcc(版本4.8.2)详细介绍
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • 在Linux系统中使用Iptables实现流量转发功能流程步骤(0个评论)
    • vim学习笔记-入门级需要了解的一些快捷键(0个评论)
    • 在centos7系统中实现分区并格式化挂载一块硬盘到/data目录流程步骤(0个评论)
    • 在Linux系统种查看某一个进程所占用的内存命令(0个评论)
    • Linux中grep命令中的10种高级用法浅析(0个评论)
    • 近期文章
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf文件功能(0个评论)
    • Laravel从Accel获得5700万美元A轮融资(0个评论)
    • 在go + gin中gorm实现指定搜索/区间搜索分页列表功能接口实例(0个评论)
    • 在go语言中实现IP/CIDR的ip和netmask互转及IP段形式互转及ip是否存在IP/CIDR(0个评论)
    • PHP 8.4 Alpha 1现已发布!(0个评论)
    • Laravel 11.15版本发布 - Eloquent Builder中添加的泛型(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2016-11
    • 2017-07
    • 2017-10
    • 2017-11
    • 2018-01
    • 2018-02
    • 2020-03
    • 2020-04
    • 2020-05
    • 2020-06
    • 2021-02
    • 2021-03
    • 2021-04
    • 2021-06
    • 2021-07
    • 2021-08
    • 2021-09
    • 2021-10
    • 2021-11
    • 2021-12
    • 2022-01
    • 2022-03
    • 2022-04
    • 2022-08
    • 2022-11
    • 2022-12
    • 2023-01
    • 2023-02
    • 2023-03
    • 2023-06
    • 2023-07
    • 2023-10
    • 2023-12
    • 2024-01
    • 2024-04
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客