Linux下安装配置nginx

一、Linux下安装配置nginx

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

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

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

     #rz

1.2 解压

[root@vw010001135067 ~]# cd /usr/local/

[root@vw010001135067 local]# tar -zxvf 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]# 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= 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= 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;#开启的进程数,一般设置CUP核心数 或者核心数量*2

#定义错误日志,以及记录的日志等级

#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;#单个进程最大连接数(最大连接数=连接数*进程数)

#use [ kqueue | rtsig | epoll | /dev/poll | select | poll ];

#use epoll; #使用epoll(linux2.6的高性能方式)

}

http {

include      mime.types; #文件扩展名与文件类型映射表

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"';

#指定日志存放路径

#access_log  logs/access.log  main;

sendfile        on;#开启高效文件传输模式,sendfile指令指定nginx是否调用sendfile函数来输出文件,对于普通应用设为 on,如果用来进行下载等应用磁盘IO重负载应用,可设置为off,以平衡磁盘与网络I/O处理速度,降低系统的负载。注意:如果图片显示不正常把这个改成off。

#tcp_nopush    on;#该选项用于防止网络阻塞

#keepalive_timeout  0;

keepalive_timeout  65; #长连接超时时间,单位是秒

gzip  on;#启用Gizp压缩

#服务器的集群

upstream  log.5i5j.com { #服务器集群名字

#server  172.16.21.13:8081 weight=1;#服务器配置  weight是权重的意思,权重越大,分配的概率越大。

#server  127.0.0.1:8080  weight=1;

server    10.9.2.49:28778 weight=1;

}

#当前的Nginx的配置

server {

listen      80;#监听80端口,可以改成其他端口

server_name  log.5i5j.com;#当前服务的域名

#charset koi8-r;#默认字符编码

#access_log  logs/host.access.log  main;

#pass路径匹配 能够匹配路径中带“/”的 不过需要注意的是如果之后也有相关“/”匹配项并且使用比此处更精确匹配符,则以之后表达式优先

#location / {

#    root  html;

#    index  index.html index.htm;access_log off;

#    access_log off; #关闭日志

#}

location / {

proxy_pass http://log.5i5j.com;

proxy_set_header Host $host;

proxy_set_header X-Forwarded-For $remote_addr;

proxy_redirect default;

proxy_connect_timeout 9000; #nginx跟后端服务器连接超时时间(代理连接超时)

proxy_send_timeout 9000; #后端服务器数据回传时间(代理发送超时)

proxy_read_timeout 9000; #连接成功后,后端服务器响应时间(代理接收超时)

}

location ~ ^/WEB-INF/ {

deny  all;

}

#图片缓存时间设置

#location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$ {

# expires 10d;

# root /opt/webRoot/xxx.xxx.com.static.images;

#}

#JS和CSS缓存时间设置

#location ~ .*.(js|css)?$ {

# expires 1h;

# root /opt/webRoot/xxx.xxx.com.static.js;

#}

#对 "/" 启用反向代理

#location / {

# proxy_pass http://127.0.0.1:88;

# proxy_redirect off;

# proxy_set_header X-Real-IP $remote_addr;

# #后端的Web服务器可以通过X-Forwarded-For获取用户真实IP

# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

# #以下是一些反向代理的配置,可选。

# proxy_set_header Host $host;

# client_max_body_size 10m; #允许客户端请求的最大单文件字节数

# client_body_buffer_size 128k; #缓冲区代理缓冲用户端请求的最大字节数,

# proxy_connect_timeout 90; #nginx跟后端服务器连接超时时间(代理连接超时)

# proxy_send_timeout 90; #后端服务器数据回传时间(代理发送超时)

# proxy_read_timeout 90; #连接成功后,后端服务器响应时间(代理接收超时)

# proxy_buffer_size 4k; #设置代理服务器(nginx)保存用户头信息的缓冲区大小

# proxy_buffers 4 32k; #proxy_buffers缓冲区,网页平均在32k以下的设置

# proxy_busy_buffers_size 64k; #高负荷下缓冲大小(proxy_buffers*2)

# proxy_temp_file_write_size 64k;

# #设定缓存文件夹大小,大于这个值,将从upstream服务器传

#}

#error_page  404              /404.html;

# redirect server error pages to the static page /50x.html

#

error_page  500 502 503 504  /50x.html;

location = /50x.html { # "/"精确的匹配,并且不再向下匹配

root  html;

}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80

#

#location ~ \.php$ { # "~ $"正则表达式匹配 一旦匹配则不再向下匹配

#    proxy_pass  http://127.0.0.1;

#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

#

#location ~ \.php$ {

#    root          html;

#    fastcgi_pass  127.0.0.1:9000;

#    fastcgi_index  index.php;

#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

#    include        fastcgi_params;

#}

# deny access to .htaccess files, if Apache's document root

# concurs with nginx's one

#

#location ~ /\.ht {

#    deny  all;

#}

#location ~* \.(txt|doc)$ { # "~*" 代表不区分大小写方式匹配

#    deny  all;#不希望访问txt|doc文件

#}

}

}

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

[root@vw010001135067 nginx]# nginx -s reload

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


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

原文链接:http://blog.csdn.net/u010416588/article/details/54379282

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,233评论 4 360
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,013评论 1 291
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,030评论 0 241
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,827评论 0 204
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,221评论 3 286
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,542评论 1 216
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,814评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,513评论 0 198
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,225评论 1 241
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,497评论 2 244
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 31,998评论 1 258
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,342评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 32,986评论 3 235
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,055评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,812评论 0 194
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,560评论 2 271
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,461评论 2 266

推荐阅读更多精彩内容