linux+nginx

下载:

进入http://nginx.org/en/download.html 下载nginx  

安装:

1.准备安装环境

安装nginx需要先将官网下载的源码进行编译,编译依赖gcc环境,如果没有gcc环境,需要安装gccyum install gcc-c++ 

PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括 perl 兼容的正则表达式库。nginxhttp模块使用pcre来解析正则表达式,所以需要在linux上安装pcre库: yum install -y pcre pcre-devel

lib库提供了很多种压缩和解压缩的方式,nginx使用zlibhttp包的内容进行gzip,所以需要在linux上安装zlib库: 

yum install -y zlib zlib-devel

OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用。nginx不仅支持http协议,还支持https(即在ssl协议上传输http),所以需要在linux安装openssl库: 

yum install -y openssl openssl-devel

2.编译安装

nginx-1.8.0.tar.gz拷贝至linux服务器

解压:

tar -zxvf nginx-1.8.0.tar.gz

cd nginx-1.8.0


1、 configure

./configure --help查询详细参数(参考本教程附录部分:nginx编译参数)

 

注意:下边将临时文件目录指定为/var/temp/nginx,需要在/var下创建tempnginx目录

创建目录:mkdir /var/temp/nginx/client -p

参数设置如下:

./configure \

--prefix=/usr/local/nginx \

--pid-path=/var/run/nginx.pid \

--lock-path=/var/lock/nginx.lock \

--error-log-path=/var/log/nginx/error.log \

--http-log-path=/var/log/nginx/access.log \

--with-http_gzip_static_module \

--with-http_ssl_module \

--with-http_v2_module \

--with-http_stub_status_module \

--with-http_ssl_module \

--with-http_realip_module \

--http-client-body-temp-path=/var/temp/nginx/client \

--http-proxy-temp-path=/var/temp/nginx/proxy \

--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \

--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \

--http-scgi-temp-path=/var/temp/nginx/scgi



1、 编译安装

make

make  install


启动nginx

cd /usr/local/nginx/sbin/

./nginx 

停止nginx

方式1,快速停止:

cd /usr/local/nginx/sbin

./nginx -s stop

此方式相当于先查出nginx进程id再使用kill命令强制杀掉进程。

 

方式2,完整停止(建议使用)

cd /usr/local/nginx/sbin

./nginx -s quit

此方式停止步骤是待nginx进程处理任务完毕进行停止。

重启nginx

方式1,先停止再启动(建议使用):

nginx进行重启相当于先停止nginx再启动nginx,即先执行停止命令再执行启动命令。

如下:

./nginx -s quit

./nginx

 

方式2,重新加载配置文件:

nginx的配置文件nginx.conf修改后,要想让配置生效需要重启nginx,使用-s reload不用先停止nginx再启动nginx即可将配置信息在nginx中生效,如下:

./nginx -s reload


ps:在nginx中配置https

# HTTPS server
    
upstream tomcat {
    server localhost:8080;
}

    server {
listen 443;
server_name www.handsomes.shop;
ssl on;
# root html;
index index.html index.htm;
ssl_certificate   cert/**********.pem;#ssl证书路径
ssl_certificate_key  cert/********.key;#ssl证书路径
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;                 #指定    加密算法
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #指定SSL服务器端支持的协议版本
ssl_prefer_server_ciphers on; #在使用SSLv3和TLS协议时指定服务器的加密算法要优先于客户端的加密算法
location / {
proxy_redirect   off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# 把 https 的协议告知 Tomcat,否则 Tomcat 可能认为是 http 的请求
proxy_set_header X-Forwarded-Proto $scheme;
# 请求转发给 Tomcat 集群处理
proxy_pass http://tomcat ;
}
}











你可能感兴趣的:(linux+nginx)