您的位置:首页 > 运维架构 > Nginx

Nginx学习笔记1-编译Nignx,搭建开发环境

2014-06-20 15:00 651 查看
下载nginx源码包,编译nginx需要指定pcre,zlib,openssl,到官网上下载源代码包:
http://www.zlib.net/ http://www.openssl.org/ http://www.pcre.org/
将这三个包下载放到/opt目录,tar -xzvf *.gz解压,然后也将nginx-0.6.32的包解压到/opt目录下,进入nginx目录,执行:

#./configure --sbin-path=/usr/local/sbin --with-http_ssl_module --with-pcre=../pcre-7.7 --with-zlib=../zlib-1.2.3 --with-openssl=../openssl-0.9.8g

#make && make install

如果在./configure时出现在错误,可能是没有安装gcc g+编译器的缘故。单独安装这两个编译器比较麻烦,ubuntu提供了build-essential来安装gcc和g++编译器
apt-get install build-essential

采用aptitude安装的时候,系统会将所有依赖的包都一并装上,但是使 用源码编译的时候就没这么智能了,我们需要找到需要的依赖包,然后手工安装,幸运的是,这并不复杂,也不多,例如pcre, ssl 和zlib,安装方法比较简单:

sudo aptitude install libpcre3 libpcre3-dev libpcrecpp0 libssl-dev zlib1g-dev


三、安装Nginx

ok,准备工作做完了,是时候开始下载、 安装Nginx了。

1、下载源代码

到Nignx官网去下载源代码

2、 解压

tar -zxvf nginx-0.6.31.tar.gz

...

cd nginx-0.6.31/

3、选择需要的编译选项

Nginx的编译选项还是不少 的,基本上都是定制位置和模块,分别是:

1)--sbin-path=/usr/local/sbin

从源码编译Nginx会安装在/usr/local/nginx目录下(你可以使用参数--prefix=<path>指定自己需要的位置),然后会将bin文件放在/usr/local/nginx/sbin/nginx,虽然比较清晰,但是和我们一般的习惯不同

(作为程序员的我们更习惯在/usr/local /sbin下寻找bin文件);

2)--with-http_ssl_module

主要是提供https访问支持的。

5、 Compile

./configure --sbin-path=/usr/local/sbin --with-http_ssl_module

编 译的时间不会很长,完成的时候你会在屏幕上看到类似下面的信息:

...

nginx path prefix: "/usr/local/nginx"

nginx binary file: "/usr/local/sbin"

nginx configuration file: "/usr/local/nginx/conf/nginx.conf"

...

留 意上面的提示,涉及到nginx的几个重要文件的路径信息。

6、Make && make install

差不多快完成了,现在make一下。

make

sudo make install

在使用make install 命令时可能会提示当前执行的命令权限不够,sudo su命令然后输入密码提升下权限就ok

7、chmod(可选)

还需要给bin文件有执行权限,也比较简单:

chmod +x /usr/local/sbin/nginx

8、Nginx重要文件安装目录

默认nginx安装的目录在/usr/local/nginx下,包括:

/usr/local/nginx/sbin #nginx启动文件

/usr/local/nginx/conf #配置文件

/usr/local/nginx/html #默认网页文件

/usr/local/nginx/logs #日志文件


四、使用

安装完成后,试着使用下。

1、启动

sudo /usr/local/sbin/nginx

然后把自己的浏览器导航到http://IP就可 以看到默认的欢迎界面了

Welcome to nginx!

If you see this page, the nginx web server is successfully installed andworking. Further configuration is required.

For online documentation and support please refer tonginx.org.

Commercial support is available atnginx.com.

Thank you for using nginx.

2、停止


六、附录:Compile-time options

(原文参考:http://wiki.codemongers.com/NginxInstallOptions

configure 脚本确定系统所具有一些特性,特别是 nginx 用来处理连接的方法。然后,它创建 Makefile 文件。

configure 支持下面的选项:

1)目录属性

--prefix=<path> - Nginx安装路径。如果没有指定,默认为 /usr/local/nginx。

--sbin-path=<path> - Nginx可执行文件安装路径。只能安装时指定,如果没有指定,默认为<prefix>/sbin/nginx。

--conf-path=<path> - 在没有给定-c选项下默认的nginx.conf的路径。如果没有指定,默认为<prefix>/conf/nginx.conf。

--pid-path=<path> - 在nginx.conf中没有指定pid指令的情况下,默认的nginx.pid的路径。如果没有指定,默认为 <prefix>/logs/nginx.pid。

--lock-path=<path> - nginx.lock文件的路径,默认为<prefix>/logs/nginx.lock

--error-log-path=<path> - 在nginx.conf中没有指定error_log指令的情况下,默认的错误日志的路径。如果没有指定,默认为 <prefix>/logs/error.log。

--http-log-path=<path> - 在nginx.conf中没有指定access_log指令的情况下,默认的访问日志的路径。如果没有指定,默认为 <prefix>/logs/access.log。

--user=<user> - 在nginx.conf中没有指定user指令的情况下,默认的nginx使用的用户。如果没有指定,默认为 nobody。

--group=<group> - 在nginx.conf中没有指定user指令的情况下,默认的nginx使用的组。如果没有指定,默认为 nobody。

--builddir=DIR - 指定编译的目录



2)模块

--with-rtsig_module - 启用 rtsig 模块

--with-select_module --without-select_module -允许或不允许开启SELECT模式,如果 configure 没有找到更合适的模式,比如:kqueue(sun os),epoll (linux kenel 2.6+), rtsig(实时信号)或者/dev/poll(一种类似select的模式,底层实现与SELECT基本相 同,都是采用轮训方法) SELECT模式将是默认安装模式

--with-poll_module --without-poll_module - Whether or not to enable the poll module. This module is enabled by default if a more suitable method such as kqueue, epoll, rtsig or /dev/poll is not discovered by configure.

--with-http_ssl_module -开启HTTP SSL模块,使NGINX可以支持HTTPS请求。这个模块需要已经安装了OPENSSL,在DEBIAN上是libssl

--with-http_realip_module - 启用 ngx_http_realip_module

--with-http_addition_module - 启用 ngx_http_addition_module

--with-http_sub_module - 启用 ngx_http_sub_module

--with-http_dav_module - 启用 ngx_http_dav_module

--with-http_flv_module - 启用 ngx_http_flv_module

--with-http_stub_status_module - 启用 "server status" 页

--without-http_charset_module - 禁用 ngx_http_charset_module

--without-http_gzip_module - 禁用 ngx_http_gzip_module. 如果启用,需要 zlib 。

--without-http_ssi_module - 禁用 ngx_http_ssi_module

--without-http_userid_module - 禁用 ngx_http_userid_module

--without-http_access_module - 禁用 ngx_http_access_module

--without-http_auth_basic_module - 禁用 ngx_http_auth_basic_module

--without-http_autoindex_module - 禁用 ngx_http_autoindex_module

--without-http_geo_module - 禁用 ngx_http_geo_module

--without-http_map_module - 禁用 ngx_http_map_module

--without-http_referer_module - 禁用 ngx_http_referer_module

--without-http_rewrite_module - 禁用 ngx_http_rewrite_module. 如果启用需要 PCRE 。

--without-http_proxy_module - 禁用 ngx_http_proxy_module

--without-http_fastcgi_module - 禁用 ngx_http_fastcgi_module

--without-http_memcached_module - 禁用 ngx_http_memcached_module

--without-http_limit_zone_module - 禁用 ngx_http_limit_zone_module

--without-http_empty_gif_module - 禁用 ngx_http_empty_gif_module

--without-http_browser_module - 禁用 ngx_http_browser_module

--without-http_upstream_ip_hash_module - 禁用 ngx_http_upstream_ip_hash_module

--with-http_perl_module - 启用 ngx_http_perl_module

--with-perl_modules_path=PATH - 指定 perl 模块的路径

--with-perl=PATH - 指定 perl 执行文件的路径

--http-log-path=PATH - Set path to the http access log

--http-client-body-temp-path=PATH - Set path to the http client request body temporary files

--http-proxy-temp-path=PATH - Set path to the http proxy temporary files

--http-fastcgi-temp-path=PATH - Set path to the http fastcgi temporary files

--without-http - 禁用 HTTP server

--with-mail - 启用 IMAP4/POP3/SMTP 代理模块

--with-mail_ssl_module - 启用 ngx_mail_ssl_module

--with-cc=PATH - 指定 C 编译器的路径

--with-cpp=PATH - 指定 C 预处理器的路径

--with-cc-opt=OPTIONS - Additional parameters which will be added to the variable CFLAGS. With the use of the system library PCRE in FreeBSD, it is necessary to indicate --with-cc-opt="-I /usr/local/include". If
we are using select() and it is necessary to increase the number of file descriptors, then this also can be assigned here: --with-cc-opt="-D FD_SETSIZE=2048".

--with-ld-opt=OPTIONS - Additional parameters passed to the linker. With the use of the system library PCRE in FreeBSD, it is necessary to indicate --with-ld-opt="-L /usr/local/lib".

--with-cpu-opt=CPU - 为特定的 CPU 编译,有效的值包括:pentium, pentiumpro, pentium3, pentium4, athlon, opteron, amd64, sparc32, sparc64, ppc64

--without-pcre - 禁止 PCRE 库的使用。同时也会禁止 HTTP rewrite 模块。在 "location" 配置指令中的正则表达式也需要 PCRE 。

--with-pcre=DIR - 指定 PCRE 库的源代码的路径。

--with-pcre-opt=OPTIONS - Set additional options for PCRE building.

--with-md5=DIR - Set path to md5 library sources.

--with-md5-opt=OPTIONS - Set additional options for md5 building.

--with-md5-asm - Use md5 assembler sources.

--with-sha1=DIR - Set path to sha1 library sources.

--with-sha1-opt=OPTIONS - Set additional options for sha1 building.

--with-sha1-asm - Use sha1 assembler sources.

--with-zlib=DIR - Set path to zlib library sources.

--with-zlib-opt=OPTIONS - Set additional options for zlib building.

--with-zlib-asm=CPU - Use zlib assembler sources optimized for specified CPU, valid values are: pentium, pentiumpro

--with-openssl=DIR - Set path to OpenSSL library sources

--with-openssl-opt=OPTIONS - Set additional options for OpenSSL building

--with-debug - 启用调试日志

--add-module=PATH - Add in a third-party module found in directory PAT
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: