Linux上搭建nginx,及简单配置

http://blog.sina.com.cn/s/blog_6734ea6d0102ux3r.html


在上家公司都是运维安装nginx,到新公司后代码开发完成部署 测试服务器要求自己装nginx,研究了好久安装好之后,到正式上线还要自己安装,索性把安装步骤自己记载下来(好大一部分都是在网站找的)。
 一,安装
  1.选定源码目录
可以是任何目录,本文选定的是/usr/local/src
cd/usr/local/src
 2.安装PCRE库
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/下载最新的PCRE源码包,使用下面命令下载编译和安装PCRE包:
cd/usr/local/src
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.33.tar.gz
tar-zxvf pcre-8.21.tar.gz
cdpcre-8.21
./configure
make
makeinstall
 3.安装zlib库
http://zlib.net/zlib-1.2.8.tar.gz下载最新的zlib源码包,使用下面命令下载编译和安装zlib包:
cd/usr/local/src
wget http://zlib.net/zlib-1.2.8.tar.gz
tar-zxvf zlib-1.2.8.tar.gz
cdzlib-1.2.8
./configure
make
makeinstall
 4.安装ssl(某些vps默认没装ssl)
cd/usr/local/src
wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz
tar-zxvfopenssl-1.0.1c.tar.gz
 5.安装nginx
Nginx一般有两个版本,分别是稳定版和开发版,您可以根据您的目的来选择这两个版本的其中一个,下面是把Nginx安装到/usr/local/nginx目录下的详细步骤:
cd/usr/local/src
wget http://nginx.org/download/nginx-1.4.2.tar.gz
tar-zxvf nginx-1.4.2.tar.gz
cdnginx-1.4.2
./configure--sbin-path=/usr/local/nginx/nginx\
--conf-path=/usr/local/nginx/nginx.conf\
--pid-path=/usr/local/nginx/nginx.pid\
--with-http_ssl_module\
--with-pcre=/usr/local/src/pcre-8.21\
--with-zlib=/usr/local/src/zlib-1.2.8\
--with-openssl=/usr/local/src/openssl-1.0.1c
make
makeinstall
--with-pcre=/usr/src/pcre-8.21指的是pcre-8.21的源码路径。
--with-zlib=/usr/src/zlib-1.2.7指的是zlib-1.2.7的源码路径。
安装成功后/usr/local/nginx目录下如下
fastcgi.confkoi-winnginx.conf.default
fastcgi.conf.defaultlogsscgi_params
fastcgi_paramsmime.typesscgi_params.default
fastcgi_params.defaultmime.types.defaultuwsgi_params
htmlnginxuwsgi_params.default
koi-utfnginx.confwin-utf
6.启动
确保系统的80端口没被其他程序占用,运行/usr/local/nginx/nginx命令来启动Nginx,
netstat-ano|grep80
如果查不到结果后执行,有结果则忽略此步骤(ubuntu下必须用sudo启动,不然只能在前台运行)
sudo/usr/local/nginx/nginx
打开浏览器访问此机器的IP,如果浏览器出现Welcometonginx!则表示Nginx已经安装并运行成功。
 二,简单配置(nginx后挂resin或者tomcat)
(标红部分为自己新加的配置)
注:只是简单的配置
http{
upstreammgame-crm{
server10.10.0.103:9080;
server10.10.0.104:9080;
}
includemime.types;
default_type application/octet-stream;
#log_formatmain'$remote_addr-$remote_user[$time_local]"$request"'
#'$status$body_bytes_sent"$http_referer"'
#'"$http_user_agent""$http_x_forwarded_for"';
#access_loglogs/access.logmain;
sendfileon;
#tcp_nopushon;
#keepalive_timeout0;
keepalive_timeout65;
#gzipon;
server{
listen80;
server_name localhost;
#charsetkoi8-r;
#access_loglogs/host.access.logmain;
location/{
roothtml;
indexindex.htmlindex.htm;
proxy_passhttp://mgame-crm;
proxy_redirectoff;
proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;
proxy_set_headerX-Real-IP$remote_addr;
proxy_set_headerHost$http_host;
access_logoff;
}
#error_page404/404.html;
#redirectservererrorpages tothestaticpage/50x.html
#
error_page500502503504/50x.html;
location=/50x.html{
roothtml;
}
#proxythePHPscriptstoApac helisteningon127.0.0.1:80
#
#location~\.php${
#proxy_passhttp://127.0.0.1;
#}
#passthePHPscriptstoFastC GIserverlisteningon127.0.0.1:9000
#
#location~\.php${
#roothtml;
#fastcgi_pass127.0.0.1:9000;


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值