linux 怎么linux上安装nginxx

linux下nginx的安装
我的图书馆
linux下nginx的安装
以Red Hat Enterprise Linux 5为例进行讲解。
相关系列:
安装nginx版本为0.8.36
一。下载nginx
下载地址:
将该下载包拷贝到/usr/local/下(随意了,找个地方就好)
cd /usr/local/
tar zxvf nginx-0.8.36.tar.gz
cd nginx-0.8.36
按照一些网络资料的介绍,执行如下命令即可完成安装
./configure
make install
但在实际安装过程中会,执行./configure时,根据系统的配置不同会有不同的错误提示,这里不罗嗦了,安装nginx需要安装openssl和&pcre,
openssl在中有过介绍,这里不再赘述,下面只介绍一下pcre的安装,如下:
下载pcre:http://sourceforge.net/projects/pcre/files/
,选择pcre-8.02.tar.gz,拷贝到/usr/local/下
tar -zxvf pcre-8.02.tar.gz
cd pcre-8.02
./configure --prefix=/usr/local/pcre
make install
ok,pcre安装完成
接着我们安装nginx,
cd /usr/local/nginx-0.8.36
./configure --prefix=/usr/local/nginx --with-pcre=/usr/local/pcre-8.02
--with-http_ssl_module --with-openssl=/usr/local/openssl-0.9.8o
make install
ok,nginx安装完成。
&修改&/usr/local/pcre/conf/nginx.conf 来满足自己的需求,下面给一个负载的小实例
Java代码 &
user&&#确保存在这个用户 &&
worker_processes&&2;
error_log&&/var/log/nginx/error.log&&#确保路径存在 &&
pid&&&&&&&&logs/nginx. &&
events&{ &&
&&&&worker_connections&&1024;
&&&&multi_accept& &&
&&&&use& &&
&&&&include&&&&&&&mime. &&
&&&&default_type&&application/octet- &&
&&&&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&&/var/log/nginx/access.log&& &&
&&&&sendfile&&&&&&&& &&
&&&&#tcp_nopush&&&&& &&
&&&&keepalive_timeout&&30;
&&&&#gzip&& &&
&&&&server_names_hash_bucket_size&128; &&
&&&&upstream&tomcats&{ &&
&&&&&&&&&server&192.168.0.104:8888&weight=3;
&&&&&&&&&server&192.168.2.94:8888&weight=2;&
&&&&&&&&&ip_ &&
&&&&server&{ &&
&&&&&&&&listen&&&&&&&80;
&&&&&&&&charset&gb2312; &&
&&&&&&&&add_header&test&private; &&
&&&&&&&&location&/&{ &&
&&&&&&&&&&&&root&&&/usr/local/test/boss/ &&
&&&&&&&&&&&&index&&index.html&index.htm&index. &&
&&&&&&&&&&&&proxy_pass&http:&&
&&&&&&&&&&&&proxy_redirect& &&
&&&&&&&&&&&&proxy_set_header&Host&$ &&
&&&&&&&&&&&&proxy_set_header&X-Real-IP&$remote_ &&
&&&&&&&&&&&&proxy_set_header&X-Forwarded-For&$proxy_add_x_forwarded_
&&&&&&&&&&&&client_max_body_size&50m; &&
&&&&&&&&&&&&client_body_buffer_size&256k; &&
&&&&&&&&&&&&proxy_connect_timeout&10; &&
&&&&&&&&&&&&proxy_send_timeout&15; &&
&&&&&&&&&&&&proxy_read_timeout&15; &&
&&&&&&&&&&&&proxy_buffer_size&4k; &&
&&&&&&&&&&&&proxy_buffers&4&32k; &&
&&&&&&&&&&&&proxy_busy_buffers_size&64k; &&
&&&&&&&&&&&&proxy_temp_file_write_size&64k; &&
&&&&&&&&} &&
&&&&&&&&error_page&&&500&502&503&504&&/50x. &&
&&&&&&&&location&=&/50x.html&{ &&
&&&&&&&&&&&&root&&& &&
&&&&&&&&} &&
}&&#确保存在这个用户
worker_processes
/var/log/nginx/error.#确保路径存在
logs/nginx.
worker_connections
default_type
application/octet-
log_format
'$remote_addr - $remote_user [$time_local] $request '
'"$status" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log
/var/log/nginx/access.
keepalive_timeout
server_names_hash_bucket_size 128;
upstream tomcats {
server 192.168.0.104:8888 weight=3;
server 192.168.2.94:8888 weight=2;
charset gb2312;
location / {
/usr/local/test/boss/
index.html index.htm index.
proxy_pass http://
proxy_set_header Host $
proxy_set_header X-Real-IP $remote_
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_
client_max_body_size 50m;
client_body_buffer_size 256k;
proxy_connect_timeout 10;
proxy_send_timeout 15;
proxy_read_timeout 15;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
error_page
500 502 503 504
location = /50x.html {
&注意,这里nginx监听80端口,所以要在iptables里打开80端口。
启动nqinx:
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
接着访问这台机器的80的端口,如果请求成功,则说明配置成功。
为了操作方便,可以自己写一个nginx命令脚本,放到/etc/init.d下,并赋予其执行权限即可,详见附件,执行方法如下:
启动:service nginx start
停止:service nginx stop
重启:service nginx reconfigure
查看状态:service nginx status
TA的最新馆藏[转]&[转]&
喜欢该文的人也喜欢温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
阅读(2954)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
loftPermalink:'',
id:'fks_',
blogTitle:'linux下nginx安装教程(本人实际操作过)',
blogAbstract:'1、下载nginx1.2.4#注:下载地址:http://nginx.org/download/nginx-1.2.4.tar.gzwget -c http://nginx.org/download/nginx-1.2.4.tar.gz&2、安装#注:默认安装到/usr/local/nginxtar -zxvf nginx-1.2.4.tar.gz cd nginx-1.2.4 ./configure &如果出现./configure: error: the HTTP rewrite module requires the PCRE library.You can',
blogTag:'',
blogUrl:'blog/static/7',
isPublished:1,
istop:false,
modifyTime:6,
publishTime:7,
permalink:'blog/static/7',
commentCount:1,
mainCommentCount:1,
recommendCount:0,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:false,
hostIntro:'',
hmcon:'1',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}linux环境下安装nginx步骤 - 进击的乌龟 - 博客园
开始前,请确认gcc g++开发类库是否装好,默认已经安装。
  ububtu平台编译环境可以使用以下指令
apt-get install build-essential
apt-get install libtool
  centos平台编译环境使用如下指令
  安装make:
yum -y install gcc automake autoconf libtool make
  安装g++:
yum install gcc gcc-c++
下面正式开始:
一、选定安装文件目录
  可以选择任何目录,本文选择 &cd /usr/local/src
cd /usr/local/src
二、安装PCRE库
  ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/&下载最新的 PCRE 源码包,使用下面命令下载编译和安装 PCRE 包:(本文参照下载文件版本:pcre-8.37.tar.gz 经过验证未发现这个版本,若想下载最新版本请打开上面网址。本文选择pcre-8.39.tar.gz)
cd /usr/local/src
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz
tar -zxvf pcre-<span style="color: #.37.tar.gz
cd pcre-<span style="color: #.34
./configure
make install
三、安装zlib库
  http://zlib.net/zlib-1.2.11.tar.gz&下载最新的 zlib 源码包,使用下面命令下载编译和安装 zlib包:(本文参照下载文件版本:zlib-1.2.8.tar.gz&经过验证未发现这个版本,若想下载最新版本请打开上面网址。本文选择zlib-1.2.11.tar.gz&)
cd /usr/local/src
wget http://zlib.net/zlib-1.2.11.tar.gz
tar -zxvf zlib-<span style="color: #.2.<span style="color: #.tar.gz
cd zlib-<span style="color: #.2.11
./configure
make install
四、安装openssl(某些vps默认没装ssl)
cd /usr/local/src
wget https://www.openssl.org/source/openssl-1.0.1t.tar.gz
tar -zxvf openssl-<span style="color: #.0.1t.tar.gz
五、安装nginx
  Nginx 一般有两个版本,分别是稳定版和开发版,您可以根据您的目的来选择这两个版本的其中一个,下面是把 Nginx 安装到 /usr/local/nginx 目录下的详细步骤:
cd /usr/local/src
wget http://nginx.org/download/nginx-1.1.10.tar.gz
tar -zxvf nginx-<span style="color: #.1.<span style="color: #.tar.gz
cd nginx-<span style="color: #.1.<span style="color: #./configuremakemake install
注:这里可能会出现报错
  按照第四步方法或者
  ubuntu下
apt-get install openssl
apt-get install libssl-dev
  centos下
yum -y install openssl openssl-devel
六、启动nginx
  因为可能apeache占用80端口,apeache端口尽量不要修改,我们选择修改nginx端口。
  linux 修改路径/usr/local/nginx/conf/nginx.conf,Windows 下 安装目录\conf\nginx.conf。
  修改端口为8090,localhost修改为你服务器ip地址。(成功就在眼前!!)
  启动nginx
netstat -ano|grep <span style="color: #
  如果查不到执行结果,则忽略上一步(ubuntu下必须用sudo启动,不然只能在前台运行)
sudo /usr/local/nginx/nginx
七、nginx重启、关闭、启动
&启动代码格式:nginx安装目录地址 -c nginx配置文件地址
[root@LinuxServer sbin]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
&nginx的停止有三种方式:
  1、查看进程号
[root@LinuxServer ~]# ps -ef|grep nginx
  2、杀死进程
[root@LinuxServer ~]# kill -QUIT 2072
1、查看进程号
[root@LinuxServer ~]# ps -ef|grep nginx
2、杀死进程
[root@LinuxServer ~]# kill -TERM 2132
或 [root@LinuxServer ~]# kill -INT 2132
[root@LinuxServer ~]# pkill -9 nginx
1、验证nginx配置文件是否正确
方法一:进入nginx安装目录sbin下,输入命令./nginx -t
看到如下显示nginx.conf syntax is ok
nginx.conf test is successful
说明配置文件正确!
方法二:在启动命令-c前加-t
&2、重启Nginx服务
&方法一:进入nginx可执行目录sbin下,输入命令./nginx -s reload&即可
方法二:查找当前nginx进程号,然后输入命令:kill -HUP 进程号 实现重启nginx服务
八、最终结果:
九、项目文件存放路径
  放到这个文件下,创建文件夹放入就好。
参考文章:/install
阅读(...) 评论()

我要回帖

更多关于 linux下安装nginx教程 的文章

 

随机推荐