程序笔记   发布时间:2022-05-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了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.

Linux下安装配置nginx详解

如上图,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详解

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

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

@H_674_230@您可能感兴趣的文章:
  • Linux下nginx编译安装教程和编译参数详解
  • Linux下tomcat+Nginx服务器环境安装配置的简明教程
  • Linux下yum安装nginx教程
  • 在linux系统下安装两个nginx的简单方法
  • linux下安装nginx(图文教程)
  • linux系统安装Nginx Lua环境
  • Linux上安装搭建Nginx服务器的详细步骤
  • linux下Nginx 0.8.40的安装方法
  • Linux下Nginx安装的方法(pcre和openssl)
  • @H_618_251@

大佬总结

以上是大佬教程为你收集整理的Linux下安装配置nginx详解全部内容,希望文章能够帮你解决Linux下安装配置nginx详解所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。