centos6.9安装及配置nginx1.19方法

centos6.9安装及配置nginx1.19方法
依赖环境

yum install -y wget 
yum install -y vim-enhanced 
yum install -y make cmake gcc gcc-c++ 
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel

下载nginx-1.19.0.tar.gz

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

编译安装
解压:

tar -zxvf nginx-1.19.0.tar.gz
//更改目录名为nginx119
cd nginx119

执行如下命令

./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/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 \
--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 \
--with-http_stub_status_module \
--with-http_ssl_module \
--http-scgi-temp-path=/var/temp/nginx/scgi

注意:上边将临时文件目录指定为/var/temp/nginx,需要在/var下创建temp/nginx目录
开始编译和安装

make
make install

安装成功查看安装目录 :

启动Nginx

启动

cd /usr/local/nginx/sbin/
./nginx

查看

ps -aux | grep nginx

打开浏览器 http:// +linux的ip:80 出现如下图表示nginx安装成功并成功访问了

退出Nginx

cd /usr/local/nginx/sbin
./nginx -s quit

重启Nginx

cd /usr/local/nginx/sbin
./nginx -s reload

反向代理负载均衡配置

配置
以vim模式打开nginx.conf配置文件

cd /usr/local/nginx/conf/
vi nginx.conf

根据上边的需求在nginx.conf文件中配置负载均衡,如下:

在server上添加此upstream节点

复制代码
upstream mytomcat{
#分权 即访问131与134的次数比例为1比1
server 需要代理的ip1 weight=1;
server 需要代理的ip2 weight=1;
}

server {
listen 80;
server_name localhost;
#即所有请求都到这里去找分配
location / {
#使用mytomcat分配规则,即刚自定义添加的upstream节点
proxy_pass http://mytomcat;
}
}

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

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       8888;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }
		#即所有请求都到这里去找分配
		location /web {           
           proxy_pass http://localhost:80/;
        }
		location /fead {
           #使用mytomcat分配规则,即刚自定义添加的upstream节点
           proxy_pass http://localhost:9999/;
        }
		location /infonet {           
           proxy_pass http://localhost:7777/infonet/;
        }

        #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;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.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;
    #    }
    #}

}

测试结果为:
http://121.42.242.230:8888/web/
http://121.42.242.230:8888/infonet/softdir/getFullTree

参考地址:
https://www.cnblogs.com/duoshou/articles/10833694.html

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页