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 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 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项目是否成功

这里写图片描述

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

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


学习编程是顺着互联网的发展潮流,是一件好事。新手如何学习编程?其实不难,不过在学习编程之前你得先了解你的目的是什么?这个很重要,因为目的决定你的发展方向、决定你的发展速度。
IT行业是什么工作做什么?IT行业的工作有:产品策划类、页面设计类、前端与移动、开发与测试、营销推广类、数据运营类、运营维护类、游戏相关类等,根据不同的分类下面有细分了不同的岗位。
女生学Java好就业吗?女生适合学Java编程吗?目前有不少女生学习Java开发,但要结合自身的情况,先了解自己适不适合去学习Java,不要盲目的选择不适合自己的Java培训班进行学习。只要肯下功夫钻研,多看、多想、多练
Can’t connect to local MySQL server through socket \'/var/lib/mysql/mysql.sock问题 1.进入mysql路径
oracle基本命令 一、登录操作 1.管理员登录 # 管理员登录 sqlplus / as sysdba 2.普通用户登录
一、背景 因为项目中需要通北京网络,所以需要连vpn,但是服务器有时候会断掉,所以写个shell脚本每五分钟去判断是否连接,于是就有下面的shell脚本。
BETWEEN 操作符选取介于两个值之间的数据范围内的值。这些值可以是数值、文本或者日期。
假如你已经使用过苹果开发者中心上架app,你肯定知道在苹果开发者中心的web界面,无法直接提交ipa文件,而是需要使用第三方工具,将ipa文件上传到构建版本,开...
下面的 SQL 语句指定了两个别名,一个是 name 列的别名,一个是 country 列的别名。**提示:**如果列名称包含空格,要求使用双引号或方括号:
在使用H5混合开发的app打包后,需要将ipa文件上传到appstore进行发布,就需要去苹果开发者中心进行发布。​
+----+--------------+---------------------------+-------+---------+
数组的声明并不是声明一个个单独的变量,比如 number0、number1、...、number99,而是声明一个数组变量,比如 numbers,然后使用 nu...
第一步:到appuploader官网下载辅助工具和iCloud驱动,使用前面创建的AppID登录。
如需删除表中的列,请使用下面的语法(请注意,某些数据库系统不允许这种在数据库表中删除列的方式):
前不久在制作win11pe,制作了一版,1.26GB,太大了,不满意,想再裁剪下,发现这次dism mount正常,commit或discard巨慢,以前都很快...
赛门铁克各个版本概览:https://knowledge.broadcom.com/external/article?legacyId=tech163829
实测Python 3.6.6用pip 21.3.1,再高就报错了,Python 3.10.7用pip 22.3.1是可以的
Broadcom Corporation (博通公司,股票代号AVGO)是全球领先的有线和无线通信半导体公司。其产品实现向家庭、 办公室和移动环境以及在这些环境...
发现个问题,server2016上安装了c4d这些版本,低版本的正常显示窗格,但红色圈出的高版本c4d打开后不显示窗格,
TAT:https://cloud.tencent.com/document/product/1340