centos服务器搭建-Nginx 1.10.3

编译环境

yum   install  -y  gcc   automake   autoconf    libtool     make

yum   install   -y   gcc    gcc-c   gcc-c++

cd      /opt

安装PCRE库   &   zlib库   &  ssl   &   nginx

http://www.pcre.org/

http://www.zlib.net/

wget   https://ftp.pcre.org/pub/pcre/pcre-8.39.tar.gz

tar  -zxvf pcre-8.39.tar.gz

cd  pcre-8.39

./configure  && make && makeinstall

cd      /opt

wget  http://www.zlib.net/zlib-1.2.11.tar.gz

tar  -zxvf  zlib-1.2.11.tar.gz

cd   zlib-1.2.11

./configure   &&   make && makeinstall

cd      /opt

wget    https://www.openssl.org/source/openssl-1.0.1t.tar.gz

tar    -zxvf   openssl-1.0.1t.tar.gz   -C    /usr/local/openssl

yum -y install   pcre   pcre-devel

yum -y install  zlib    zlib-devel

yum -y install  openssl   openssl-devel

cd      /opt

wget   http://nginx.org/download/nginx-1.10.3.tar.gz

tar-zxvf  nginx-1.10.3.tar.gz

cd    nginx-1.10.3

./configure  --prefix=/usr/local/nginx 

--with-http_stub_status_module 

--without-http-cache

--with-http_ssl_module

--with-http_gzip_static_module

--with-pcre=/ opt/pcre-8.39

--with-zlib=/ opt/zlib-1.2.11

--with-openssl=/usr/local/openssl

Configurationsummary

  + using system PCRE library

  + using system OpenSSL library

  + md5: using OpenSSL library

  + sha1: using OpenSSL 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 temporaryfiles: "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"

make   && make install

######################################################

--with-pcre=/usr/src/pcre-8.34指的是pcre-8.34 的源码路径。

--with-zlib=/usr/src/zlib-1.2.7指的是zlib-1.2.7 的源码路径。

--with-openssl=/opt/app/openet/oetal1/chenhe/openssl-1.0.1t  指的是openssl-1.0.1t源码路径。

nginx的configure命令支持以下参数:

--prefix=path    定义一个目录,存放服务器上的文件 ,也就是nginx的安装目录。默认使用 /usr/local/nginx。

--sbin-path=path 设置nginx的可执行文件的路径,默认为  prefix/sbin/nginx.

--conf-path=path  设置在nginx.conf配置文件的路径。nginx允许使用不同的配置文件启动,通过命令行中的-c选项。默认为prefix/conf/nginx.conf.

--pid-path=path  设置nginx.pid文件,将存储的主进程的进程号。安装完成后,可以随时改变的文件名, 在nginx.conf配置文件中使用 PID指令。默认情况下,文件名 为prefix/logs/nginx.pid.

--error-log-path=path设置主错误,警告,和诊断文件的名称。安装完成后,可以随时改变的文件名 ,在nginx.conf配置文件中 使用的error_log指令。默认情况下,文件名 为prefix/logs/error.log.

--http-log-path=path  设置主请求的HTTP服务器的日志文件的名称。安装完成后,可以随时改变的文件名,在nginx.conf配置文件中 使用 的access_log指令。默认情况下,文件名 为prefix/logs/access.log.

--user=name  设置nginx工作进程的用户。安装完成后,可以随时更改的名称在nginx.conf配置文件中使用的 user指令。默认的用户名是nobody。

--group=name  设置nginx工作进程的用户组。安装完成后,可以随时更改的名称在nginx.conf配置文件中使用的 user指令。默认的为非特权用户。

--with-select_module--without-select_module 启用或禁用构建一个模块来允许服务器使用select()方法。该模块将自动建立,如果平台不支持的kqueue,epoll,rtsig或/dev/poll。

--with-poll_module--without-poll_module 启用或禁用构建一个模块来允许服务器使用poll()方法。该模块将自动建立,如果平台不支持的kqueue,epoll,rtsig或/dev/poll。

--without-http_gzip_module— 不编译压缩的HTTP服务器的响应模块。编译并运行此模块需要zlib库。

--without-http_rewrite_module  不编译重写模块。编译并运行此模块需要PCRE库支持。

--without-http_proxy_module— 不编译http_proxy模块。

--with-http_ssl_module— 使用https协议模块。默认情况下,该模块没有被构建。建立并运行此模块的OpenSSL库是必需的。

--with-pcre=path — 设置PCRE库的源码路径。PCRE库的源码(版本4.4 -8.30)需要从PCRE网站下载并解压。其余的工作是Nginx的./ configure和make来完成。正则表达式使用在location指令和ngx_http_rewrite_module 模块中。

--with-pcre-jit—编译PCRE包含“just-in-time compilation”(1.1.12中,pcre_jit指令)。

--with-zlib=path —设置的zlib库的源码路径。要下载从 zlib(版本1.1.3 -1.2.5)的并解压。其余的工作是Nginx的./ configure和make完成。ngx_http_gzip_module模块需要使用zlib 。

--with-cc-opt=parameters— 设置额外的参数将被添加到CFLAGS变量。例如,当你在FreeBSD上使用PCRE库时需要使用:--with-cc-opt="-I/usr/local/include。.如需要需要增加 select()支持的文件数量:--with-cc-opt="-DFD_SETSIZE=2048".

--with-ld-opt=parameters—设置附加的参数,将用于在链接期间。例如,当在FreeBSD下使用该系统的PCRE库,应指定:--with-ld-opt="-L/usr/local/lib".

启动

确保系统的 80端口没被其他程序占用,运行/usr/local/nginx/sbin/nginx 命令来启动 Nginx

sudo  /usr/local/nginx/sbin/nginx

netstat  -ano|grep  80

打开浏览器访问此机器的 IP,如果浏览器出现 Welcometo nginx! 则表示 Nginx 已经安装并运行成功。

如果你需要处理php脚本的话,还需要安装php-fpm

vim  /etc/init.d/nginx

内容附文件

chmod    755  /etc/init.d/nginx

service nginx  start[stop/restart]


配置文件

cd     /usr/local/nginx/conf

cp  nginx.conf  nginx.conf.bak

        拷贝 nginx.conf    &   proxy.conf

配置nginx做反向代理

[root@localhost opt]# cat /proc/cpuinfo| grep "processor"| wc -l

4

修改 worker_processes  4;

更改nginx配置文件/usr/local/nginx/conf/nginx.conf,添加一个server节点

server

{

listen      80 default_server;

server_name  localhost;

indexindex.jsp index.html;

root /home/default;

location~ .* {

proxy_passhttp://127.0.0.1:9000;

proxy_set_headerX-Real-IP $remote_addr;

}

}

proxy_pass http://127.0.0.1:9000 这一行的端口必须与前面tomcat的端口一致

原文地址:https://www.cnblogs.com/ncepu/p/13695095.html