Nginx安装配置

目录

 

一、安装编译工具及库文件

二、首先要安装 PCRE

2、解压安装包:

3、进入安装包目录

4、编译安装 

5、查看pcre版本

安装 Nginx

2、解压安装包

3、进入安装包目录

4、编译安装

5、查看nginx版本

Nginx 配置

配置nginx.conf

检查配置文件ngnix.conf


一、安装编译工具及库文件

yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel

二、首先要安装 PCRE

该文件为正则表达式库。让Nginx支持rewrite需要安装这个库。

1、下载 PCRE安装包

下载地址: https://sourceforge.net/projects/pcre/files/pcre/

[root@zfr src]# wget http://downloads.sourceforge.net/project/pcre/pcre/8.41/pcre-8.41.tar.gz

2、解压安装包:

[root@zfr src]# tar -zxvf pcre-8.41.tar.gz

3、进入安装包目录

[root@zfr src]# cd pcre-8.41

4、编译安装 

[root@bzfr pcre-8.41]# ./configure

[root@zfr pcre-8.41]# make && make install

5、查看pcre版本

[root@zfr pcre-8.41]# pcre-config--version

安装 Nginx

1、下载 Nginx

可以选择自己需要的版本

下载地址:http://nginx.org/en/download.html 

[root@zfr src]# wget http://nginx.org/download/nginx-1.10.3.tar.gz

2、解压安装包

[root@zfr src]# tar -zxvf nginx-1.10.3.tar.gz

3、进入安装包目录

[root@zfr src]# cd nginx-1.10.3

4、编译安装

[root@zfr nginx-1.10.3]# ./configure--prefix=/home/nginx--with-http_stub_status_module--with-http_ssl_module--with-pcre=/usr/local/src/pcre-8.41

[root@zfr nginx-1.10.3]# make

[root@zfr nginx-1.10.3]# make install

5、查看nginx版本

[root@zfr nginx-1.10.3]# /home/nginx/sbin/nginx-v

Nginx 配置

配置nginx.conf

[root@zfr conf]#  vi /nginx/conf/nginx.conf

配置文件如下

#user  nobody;    #工作用户
worker_processes  4;   #工作线程数,建议和CPU内核数一样


#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;   #错误日志级别

#pid        logs/nginx.pid;    #pid的存放路径

events {
    worker_connections  10240;    #同时接收的网络连接数
}

http {
    include       mime.types;       #其中定义了一个types结构,包含了浏览器能够识别的MIME类型以及对应相关类型的文件的后缀名。
    default_type  application/octet-stream;     #默认值为text/plain 为types模块定义的application/octet-stream


    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" $hostname $server_name  '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" $http_x_forwarded_for $upstream_cache_status '
                      '"$upstream_http_content_type" $request_time $upstream_response_time $bytes_sent $request_length '
                      '"$upstream_addr"';


    #access_log  logs/accesstest.log  main;
      access_log  /home/ycm/nginxbin/logs/host.access.log main;


    sendfile        on;      #使用sendfile()传输文件

    #sendfile_max_chunk size; #size大于0,每个work process每次调用传输的数据量不能超过这个。默认为0无限制。

    #tcp_nopush     on;   
    client_max_body_size 50M;  
    keepalive_timeout  65;     #连接超时时间,默认为75s。

    #gzip  on;

upstream receiver{
             server 10.3.5.XX:6101;
         }
upstream heartbeat{
             server 10.3.5.XX:6201;
         }
upstream query{
             server 10.3.5.XX:6107;
         }
upstream webapp{
             server 10.3.5.XX:8080;
         }
upstream gf{
             server 10.3.5.XX:3000;
         }
upstream realtime{
             server 10.3.5.XX:6108;
         }
upstream graphquery{
             server 10.3.5.XX:6202;
         }
upstream manager{
             server 10.3.5.XX:6109;
         }
upstream openapi{
             server 10.3.5.XX:8106;
             server 10.3.5.XX:8106;
        }
upstream cloudsync{
             server 10.3.5.XX:6809;
        }
upstream weixin{
             server 10.3.5.XX:6105;
        }


server {
        listen       80;
        server_name XX.XX.XX.XX ;

        #charset koi8-r;
        #access_log  /home/ycm/nginxbin/logs/host.access.log combined gzip flush=5m ;
         access_log  /home/ycm/nginxbin/logs/host.access.log main;

        location / {
            root   html;
            index  index.html index.htm;
                   proxy_pass http://webapp;
                   proxy_set_header        Host            $host;
                   proxy_set_header        X-Real-IP       $remote_addr;  #一般的web服务器用这个 X-Real-IP 来获取源IP
                   proxy_set_header        x-forwarded-for $proxy_add_x_forwarded_for;  #如果nginx 服务器是作为反向代理服务器的,则这个配置项是必须的;否则看不到源IP
                   rewrite ^/$ /ycm-appmonitor/ redirect;
        }
       location /heartbeat {
            root   html;
            index  index.html index.htm;
                   proxy_pass http://heartbeat;
                   rewrite ^/$ /ycm-appmonitor/ redirect;
        }

        location /send {
            root   html;
            index  index.html index.htm;
                   proxy_pass http://openapi;
                   proxy_set_header        Host            $host;
                   proxy_set_header        X-Real-IP       $remote_addr;  #一般的web服务器用这个 X-Real-IP 来获取源IP
                   proxy_set_header        x-forwarded-for $proxy_add_x_forwarded_for;  #如果nginx 服务器是作为反向代理服务器的,则这个配置项是必须的;否则看不到源IP
                   rewrite ^/$ /ycm-appmonitor/ redirect;
        }

        #云同步的接口url错误,这个url直接成功
        location /send/api/visit {
              return 200 '{"result":"ok","nginx":"true"}';
        }


        location /api {
            root   html;
            index  index.html index.htm;
                   proxy_pass http://openapi;
                   proxy_set_header        Host            $host;
                   proxy_set_header        X-Real-IP       $remote_addr;  #一般的web服务器用这个 X-Real-IP 来获取源IP
                   proxy_set_header        x-forwarded-for $proxy_add_x_forwarded_for;  #如果nginx 服务器是作为反向代理服务器的,则这个配置项是必须的;否则看不到源IP
        }

            location /graphquery {
             root   html;
             index  index.html index.htm;
                    proxy_pass http://graphquery;
                    rewrite ^/$ /ycm-appmonitor/ redirect;
           }
            location /render {
             root   html;
             index  index.html index.htm;
                    proxy_set_header Authorization "Bearer eyJrIjoidnhXVnVjTkVWVW5McEx1NDhDWTd4aVZyWGdRb3BDTnIiLCJuIjoid2FuZ2hiayIsImlkIjoxfQ==";
                    proxy_set_header Cache-Control "max-age=3600";
                    add_header Access-Control-Allow-Origin *;
                    proxy_pass http://gf;
        }
           location /realtime {
            root   html;
            index  index.html index.htm;
                    add_header Access-Control-Allow-Origin *;
                    proxy_pass http://realtime;
        }
           location /manager{
            root   html;
            index  index.html index.htm;
                   proxy_pass http://manager;
        }
           location /sync{
            root   html;
            index  index.html index.htm;
                   proxy_pass http://cloudsync;
        }
           location /dashboard-solo {
            root   html;
            index  index.html index.htm;
                   proxy_set_header Authorization "Bearer eyJrIjoidnhXVnVjTkVWVW5McEx1NDhDWTd4aVZyWGdRb3BDTnIiLCJuIjoid2FuZ2hiayIsImlkIjoxfQ==";
                   proxy_set_header Cache-Control "max-age=3600";
                   add_header Access-Control-Allow-Origin *;
                   proxy_pass http://gf;
        }
           location /dashboard {
            root   html;
            index  index.html index.htm;
                    proxy_pass http://gf;
                    proxy_set_header Authorization "Bearer eyJrIjoidnhXVnVjTkVWVW5McEx1NDhDWTd4aVZyWGdRb3BDTnIiLCJuIjoid2FuZ2hiayIsImlkIjoxfQ==";
                    proxy_set_header Cache-Control "max-age=3600";
                    add_header Access-Control-Allow-Origin *;
        }
           location /api/datasources {
            root   html;
            index  index.html index.htm;
                    proxy_pass http://gf;
                    proxy_set_header Authorization "Bearer eyJrIjoidnhXVnVjTkVWVW5McEx1NDhDWTd4aVZyWGdRb3BDTnIiLCJuIjoid2FuZ2hiayIsImlkIjoxfQ==";
                    proxy_set_header Cache-Control "max-age=3600";
                    add_header Access-Control-Allow-Origin *;
        }


        #error_page  404              /404.html;


        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }


        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}


        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}


        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;


    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
server {
        listen       6060;
        server_name  10.3.5.40;


        #charset koi8-r;


        #access_log  logs/host.access.log  main;
                access_log  /home/ycm/nginxbin/logs/host.access.log main;


        location / {
            #root   html;
            #index  index.html index.htm;
                        #proxy_set_header Authorization "Bearer eyJrIjoiSGlpd2V3aGlFWlFONDdham9EUHQzNjdxUVBWbE1vWlMiLCJuIjoid2FuZ2hiayIsImlkIjoxfQ==";
                        proxy_pass http://receiver;
        }
                }


server {
        listen       6061;
        server_name  10.3.5.40;


        #charset koi8-r;


        #access_log  logs/host.access.log  main;
                access_log  /home/ycm/nginxbin/logs/host.access.log main;


        location / {
            #root   html;
            #index  index.html index.htm;
                        #proxy_set_header Authorization "Bearer eyJrIjoiSGlpd2V3aGlFWlFONDdham9EUHQzNjdxUVBWbE1vWlMiLCJuIjoid2FuZ2hiayIsImlkIjoxfQ==";
                        proxy_pass http://heartbeat;
        }
                }


server {
        listen       6062;
        server_name  10.3.5.40;


        #charset koi8-r;


        #access_log  logs/host.access.log  main;
                access_log  /home/ycm/nginxbin/logs/host.access.log main;


        location / {
            #root   html;
            #index  index.html index.htm;
                        #proxy_set_header Authorization "Bearer eyJrIjoiSGlpd2V3aGlFWlFONDdham9EUHQzNjdxUVBWbE1vWlMiLCJuIjoid2FuZ2hiayIsImlkIjoxfQ==";
                        proxy_pass http://query;
        }
                }
server {
        listen       6105;
        server_name  10.3.5.40;


        #charset koi8-r;


        #access_log  logs/host.access.log  main;
                access_log  /home/ycm/nginxbin/logs/host.access.log main;


        location /msg/weixin/access {
            #root   html;
            #index  index.html index.htm;
                        proxy_pass http://weixin;
        }
                }
#HTTPS server


server {
        listen       443 ssl;
        server_name  60.205.85.147 yyy.yonyoucloud.com 10.3.5.40 yyy.yonyou.com 60.205.84.199;
                access_log  /home/ycm/nginxbin/logs/host.access.log main;


        ssl_certificate      /home/ycm/nginxbin/crt/_.yonyou.com_bundle.crt;
        ssl_certificate_key  /home/ycm/nginxbin/crt/_.yonyou.com.key;


        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;


        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;


        location / {
            root   html;
            index  index.html index.htm;
            proxy_pass http://webapp;
            rewrite ^/$ /ycm-appmonitor/ redirect;
        }
    }
}

检查配置文件ngnix.conf

[root@zfr conf]# /home/nginx/sbin/nginx -t

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值