全网整合营销服务商

电脑端+手机端+微信端=数据同步管理

免费咨询热线:400-708-3566

Linux下安装配置nginx详解

一、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_64
checking 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 gcc
gcc:

安装gcc

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

安装成功后再次查看

[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

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=<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_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=<path> option.

如果有这个错误 那么执行

yum install zlib-devel

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 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 –with-http_ssl_module

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

1.4.2 启用“server+status”页,执行./configure –with-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 configure
export NGINX_HOME=/usr/local/nginx-1.10.2
export PATH=$PATH:$NGINX_HOME/sbin

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

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

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

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

编译完保存退出并执行

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

使配置生效。

1.7 查看nginx版本

[root@vw010001135067 nginx]# nginx -v
nginx 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  # nginx  # 安装配置  # 配置  # linux下nginx配置  # windows系统安装配置nginx环境  # Nginx安装配置详解  # win10安装配置nginx的过程  # Linux服务器下安装配置Nginx的教程  # Windows Server 2016 Nginx 安装配置详细图文教程  # LNMP编译安装之nginx安装配置方法图文教程  # Windows下Nginx安装配置教程  # Nginx安装配置的实现示例  # 默认为  # 配置文件  # 报错  # 好了  # 多个  # 你想  # 错了  # 注意到  # 弹出  # 自定义  # 如图  # 重启  # 压缩包  # 好后  # 大家多多  # 不设  # 默认值  # 没有安装  # 连接数  # 端口号 


相关文章: 建站之星安装模板失败:服务器环境不兼容?  公司门户网站制作流程,华为官网怎么做?  建站之星如何优化SEO以实现高效排名?  ,如何利用word制作宣传手册?  北京网站制作的公司有哪些,北京白云观官方网站?  天河区网站制作公司,广州天河区如何办理身份证?需要什么资料有预约的网站吗?  网站app免费制作软件,能免费看各大网站视频的手机app?  建站主机选择指南:服务器配置与SEO优化实战技巧  如何在建站之星绑定自定义域名?  建站之星后台管理如何实现高效配置?  如何用IIS7快速搭建并优化网站站点?  如何选择最佳自助建站系统?快速指南解析优劣  高防服务器:AI智能防御DDoS攻击与数据安全保障  如何通过主机屋免费建站教程十分钟搭建网站?  网站制作外包价格怎么算,招聘网站上写的“外包”是什么意思?  ,巨量百应是干嘛的?  专业网站设计制作公司,如何制作一个企业网站,建设网站的基本步骤有哪些?  ,想在网上投简历,哪几个网站比较好?  浅谈Javascript中的Label语句  如何用免费手机建站系统零基础打造专业网站?  制作网站软件推荐手机版,如何制作属于自己的手机网站app应用?  网站按钮制作软件,如何实现网页中按钮的自动点击?  建站之星如何实现PC+手机+微信网站五合一建站?  香港服务器网站生成指南:免费资源整合与高速稳定配置方案  常州企业网站制作公司,全国继续教育网怎么登录?  Swift中循环语句中的转移语句 break 和 continue    武清网站制作公司,天津武清个人营业执照注销查询系统网站?  制作营销网站公司,淘特是干什么用的?  h5网站制作工具有哪些,h5页面制作工具有哪些?  Android滚轮选择时间控件使用详解  手机钓鱼网站怎么制作视频,怎样拦截钓鱼网站。怎么办?  成都品牌网站制作公司,成都营业执照年报网上怎么办理?  如何配置WinSCP新建站点的密钥验证步骤?  Android使用GridView实现日历的简单功能  深圳网站制作平台,深圳市做网站好的公司有哪些?  公司网站制作费用多少,为公司建立一个网站需要哪些费用?  网站制作公司广州有几家,广州尚艺美发学校网站是多少?  制作网站怎么制作,*游戏网站怎么搭建?  招商网站制作流程,网站招商广告语?  如何正确下载安装西数主机建站助手?  深圳企业网站制作设计,在深圳如何网上全流程注册公司?  电商平台网站制作流程,电商网站如何制作?  香港服务器网站卡顿?如何解决网络延迟与负载问题?  官网自助建站平台指南:在线制作、快速建站与模板选择全解析  ppt在线制作免费网站推荐,有什么下载免费的ppt模板网站?  北京制作网站的公司,北京铁路集团官方网站?  如何在万网开始建站?分步指南解析  微信小程序 input输入框控件详解及实例(多种示例)  简历在线制作网站免费版,如何创建个人简历? 

您的项目需求

*请认真填写需求信息,我们会在24小时内与您取得联系。