nginx安装部署《简单版》

===========================================================================================

1 源码方式:安装Nginx ------------------------------------------------------------

下载:wget http://nginx.org/download/nginx-1.10.0.tar.gz
解压: tar -zxvf nginx-1.10.0.tar.gz

2 检查安装依赖:---------------------------------------------------------------------

1、GCC
2、PCRE (perl compatible regular Expressions,Perl 兼容正则表达式)
3、Zlib
4、OpenSSL

命令:yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel

3 Linux内核参数优化 ----------------------------------------------------------------

即修改/etc/sysctl.conf

修改后,再执行 sysctl -p命令,使修改生效;

4 配置安装选项 -----------------------------------------------------------------------

通常nginx安装再/opt或/usr/local目录下
配置安装目录命令:./configure -prefix=/usr/local/nginx_home --sbin-path=/usr/local/nginx_home/sbin/nginx

若未配置安装目录,默认安装到/usr/local/nginx

注意:如果需要配置ssl或其它插件,则需要执行如下命令

~] ./configure --prefix=/usr/local/nginx_home --sbin-path=/usr/local/nginx_home/sbin/nginx --with-http_ssl_module

5 编译与安装 ---------------------------------------------------------------------

编译:make
安装:make install

6 配置代理 ------------------------------------------------------------------------

主要配置:/usr/local/nginx_home/conf/nginx.conf文件即可

可参考如下配置:

[root@txdevitap03 app_comm]# cat /usr/local/nginx_home/conf/nginx.conf

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {
    worker_connections  1024;
}
 
http {
    include       mime.types;
    default_type  application/octet-stream;

    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  /usr/local/nginx_home/logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost; 
        location / {
            root   html;
            index  index.html index.htm;
        } 
    }
 
    upstream xxxxxAAAapi {
       server 172.16.1.2:8026;
       keepalive 2000;
    }
    
    upstream xxxxBBBapi {
       server 172.16.1.3:8025;
       keepalive 2000;
    }

    # HTTPS server 
    server {
        listen       443 ssl;
        server_name  dev.main.com;

        ssl                  on;
        ssl_certificate      /usr/local/nginx_home/cert/xxxxx.com.pem;
        ssl_certificate_key  /usr/local/nginx_home/cert/xxxxx.com.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;
           
        access_log  /usr/local/nginx_home/logs/https-access.log;
        error_log   /usr/local/nginx_home/logs/https-error.log;
        
        location / {
            root   html;
            index  index.html index.htm;
        }
        
        location /xxxxBBB/ {
             proxy_pass http://xxxxBBBapi;
             proxy_http_version 1.1;
             proxy_set_header Connection "";
        }
        
        location /xxxxxAAA/ {
             proxy_pass http://xxxxxAAAapi;
             
             proxy_set_header Host $host:$server_port;
             proxy_set_header Proxy-Client-IP $remote_addr;
             proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
        }

        location /xxxxxAAA/ {
             proxy_pass http://xxxxxAAAapi;
             
             proxy_set_header Host $host:$server_port;
             proxy_set_header Proxy-Client-IP $remote_addr;
             proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
        }
  
    }

}

 

7 启动、停止、重启 --------------------------------------------------------------

启动:/opt/nginx/sbin/nginx -p /opt/nginx
-p 指定Nginx的目录,因为同一台服务器可以运行多个Nginx实例,所以需要指定当前实例的目录。

~] /opt/nginx/sbin/nginx -t -c /path/to/nginx.conf  // 启动并测试nginx配置文件
~] /opt/nginx/sbin/nginx -c /path/to/nginx.conf     // 直接启动nginx

~] kill -HUP 主进程号                 // 平滑重启nginx
~] /opt/nginx/sbin/nginx -s  reload  // 重载配置文件
~] /opt/nginx/sbin/nginx -s quit     // 完整有序的停止nginx服务
~] /opt/nginx/sbin/nginx -s stop     // 快速停止nginx服务
其他的停止nginx 方式:
~] ps -ef | grep nginx
~] kill -QUIT 主进程号     // 从容停止Nginx
~] kill -TERM 主进程号     // 快速停止Nginx
~] pkill -9 nginx         // 强制停止Nginx

 

===========================================================================================
使用configure 命令参数可以再新编译的Nginx程序里做如下工作:
1、打包指定模块
2、去除指定的模块
这样就可以自定义Nginx功能,并减少内存使用;

posted @ 2020-11-13 18:22  OutPointException  阅读(174)  评论(0编辑  收藏  举报