热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

linux下安装nginx详解和与tomcat的使用

喝水勿忘打井人,转载地址:http:blog.csdn.netu010416588articledetails54379282一、Linux下安装配置

喝水勿忘打井人,转载地址:http://blog.csdn.net/u010416588/article/details/54379282

一、Linux下安装配置nginx


第一次安装nginx,中间出现的问题一步步解决。 
用到的工具secureCRT,连接并登录服务器。

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

#rz

  • 1
  • 1

1.2 解压

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

  • 1
  • 2
  • 1
  • 2

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

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

  • 1
  • 2
  • 1
  • 2

报错如下:

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

  • 1
  • 2
  • 3
  • 4
  • 5
  • 1
  • 2
  • 3
  • 4
  • 5

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

1.3.1 安装gcc

查看gcc

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

  • 1
  • 2
  • 1
  • 2

安装gcc

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

  • 1
  • 1

安装成功后再次查看

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

  • 1
  • 2
  • 1
  • 2

gcc安装好了。

1.3.2 继续执行./configure

[root@vw010001135067 nginx-1.10.2]# ./configure
checking for OS+ Linux 2.6.32-431.el6.x86_64 x86_64
checking for C compiler ... found
......
checking for PCRE library ... not found
checking for PCRE library in /usr/local/ ... not found
checking for PCRE library in /usr/include/pcre/ ... not found
checking for PCRE library in /usr/pkg/ ... not found
checking 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_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre= option.

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

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

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

  • 1
  • 1

1.3.3 再次执行./configure

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

  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

如果有这个错误 那么执行

yum install zlib-devel

  • 1
  • 1

1.3.4 执行./configure后没有报错

[root@vw010001135067 nginx-1.10.2]# ./configure
checking for OS+ Linux 2.6.32-431.el6.x86_64 x86_64
checking 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 librarynginx 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
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27

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
  • 2
  • 1
  • 2

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

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

  • 1
  • 1

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

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

  • 1
  • 1

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

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

  • 1
  • 1

1.5 上面configure就通过了

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

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

  • 1
  • 2
  • 1
  • 2

至此,nginx 执行成功了

1.6 配置环境变量

在/etc/profile 中加入配置 
打开配置文件

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

  • 1
  • 1

在配置文件中加入

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

  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

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

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

  • 1
  • 2
  • 1
  • 2

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

#nginx configure
export NGINX_HOME=/usr/local/nginx
export PATH=$PATH:$NGINX_HOME/sbin

  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

编译完保存退出并执行

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

  • 1
  • 1

使配置生效。

1.7 查看nginx版本

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

  • 1
  • 2
  • 1
  • 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

  • 1
  • 2
  • 1
  • 2

启动成功,在浏览器打开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;#最大连接数,默认为512accept_mutex on; #设置网路连接序列化,防止惊群现象发生,默认为onmulti_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;
} }
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73

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

[root@vw010001135067 nginx]# nginx -s reload

  • 1
  • 1

在浏览器调用upload项目是否成功 
这里写图片描述

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








推荐阅读
  • Linux服务器密码过期策略、登录次数限制、私钥登录等配置方法
    本文介绍了在Linux服务器上进行密码过期策略、登录次数限制、私钥登录等配置的方法。通过修改配置文件中的参数,可以设置密码的有效期、最小间隔时间、最小长度,并在密码过期前进行提示。同时还介绍了如何进行公钥登录和修改默认账户用户名的操作。详细步骤和注意事项可参考本文内容。 ... [详细]
  • 本文介绍了设计师伊振华受邀参与沈阳市智慧城市运行管理中心项目的整体设计,并以数字赋能和创新驱动高质量发展的理念,建设了集成、智慧、高效的一体化城市综合管理平台,促进了城市的数字化转型。该中心被称为当代城市的智能心脏,为沈阳市的智慧城市建设做出了重要贡献。 ... [详细]
  • Java序列化对象传给PHP的方法及原理解析
    本文介绍了Java序列化对象传给PHP的方法及原理,包括Java对象传递的方式、序列化的方式、PHP中的序列化用法介绍、Java是否能反序列化PHP的数据、Java序列化的原理以及解决Java序列化中的问题。同时还解释了序列化的概念和作用,以及代码执行序列化所需要的权限。最后指出,序列化会将对象实例的所有字段都进行序列化,使得数据能够被表示为实例的序列化数据,但只有能够解释该格式的代码才能够确定数据的内容。 ... [详细]
  • 本文介绍了在Hibernate配置lazy=false时无法加载数据的问题,通过采用OpenSessionInView模式和修改数据库服务器版本解决了该问题。详细描述了问题的出现和解决过程,包括运行环境和数据库的配置信息。 ... [详细]
  • [译]技术公司十年经验的职场生涯回顾
    本文是一位在技术公司工作十年的职场人士对自己职业生涯的总结回顾。她的职业规划与众不同,令人深思又有趣。其中涉及到的内容有机器学习、创新创业以及引用了女性主义者在TED演讲中的部分讲义。文章表达了对职业生涯的愿望和希望,认为人类有能力不断改善自己。 ... [详细]
  • baresip android编译、运行教程1语音通话
    本文介绍了如何在安卓平台上编译和运行baresip android,包括下载相关的sdk和ndk,修改ndk路径和输出目录,以及创建一个c++的安卓工程并将目录考到cpp下。详细步骤可参考给出的链接和文档。 ... [详细]
  • 本文介绍了高校天文共享平台的开发过程中的思考和规划。该平台旨在为高校学生提供天象预报、科普知识、观测活动、图片分享等功能。文章分析了项目的技术栈选择、网站前端布局、业务流程、数据库结构等方面,并总结了项目存在的问题,如前后端未分离、代码混乱等。作者表示希望通过记录和规划,能够理清思路,进一步完善该平台。 ... [详细]
  • CF:3D City Model(小思维)问题解析和代码实现
    本文通过解析CF:3D City Model问题,介绍了问题的背景和要求,并给出了相应的代码实现。该问题涉及到在一个矩形的网格上建造城市的情景,每个网格单元可以作为建筑的基础,建筑由多个立方体叠加而成。文章详细讲解了问题的解决思路,并给出了相应的代码实现供读者参考。 ... [详细]
  • 如何在服务器主机上实现文件共享的方法和工具
    本文介绍了在服务器主机上实现文件共享的方法和工具,包括Linux主机和Windows主机的文件传输方式,Web运维和FTP/SFTP客户端运维两种方式,以及使用WinSCP工具将文件上传至Linux云服务器的操作方法。此外,还介绍了在迁移过程中需要安装迁移Agent并输入目的端服务器所在华为云的AK/SK,以及主机迁移服务会收集的源端服务器信息。 ... [详细]
  • 开发笔记:Java是如何读取和写入浏览器Cookies的
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了Java是如何读取和写入浏览器Cookies的相关的知识,希望对你有一定的参考价值。首先我 ... [详细]
  • 如何搭建Java开发环境并开发WinCE项目
    本文介绍了如何搭建Java开发环境并开发WinCE项目,包括搭建开发环境的步骤和获取SDK的几种方式。同时还解答了一些关于WinCE开发的常见问题。通过阅读本文,您将了解如何使用Java进行嵌入式开发,并能够顺利开发WinCE应用程序。 ... [详细]
  • 本文介绍了在CentOS上安装Python2.7.2的详细步骤,包括下载、解压、编译和安装等操作。同时提供了一些注意事项,以及测试安装是否成功的方法。 ... [详细]
  • Oracle优化新常态的五大禁止及其性能隐患
    本文介绍了Oracle优化新常态中的五大禁止措施,包括禁止外键、禁止视图、禁止触发器、禁止存储过程和禁止JOB,并分析了这些禁止措施可能带来的性能隐患。文章还讨论了这些禁止措施在C/S架构和B/S架构中的不同应用情况,并提出了解决方案。 ... [详细]
  • 本文记录了在vue cli 3.x中移除console的一些采坑经验,通过使用uglifyjs-webpack-plugin插件,在vue.config.js中进行相关配置,包括设置minimizer、UglifyJsPlugin和compress等参数,最终成功移除了console。同时,还包括了一些可能出现的报错情况和解决方法。 ... [详细]
  • GreenDAO快速入门
    前言之前在自己做项目的时候,用到了GreenDAO数据库,其实对于数据库辅助工具库从OrmLite,到litePal再到GreenDAO,总是在不停的切换,但是没有真正去了解他们的 ... [详细]
author-avatar
起薪d这帖
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有