nignx的部署安装和反向代理

2 安装Nginx前,须要先安装 PCRE 库 如已经安装,请略过:php

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-7.7.tar.gzhtml

tar zxvf pcre-7.7.tar.gznginx

cd pcre-7.7浏览器

./configure服务器

makesession

make install
--------------------- 
做者:Tomcat猫 
来源:CSDN 
原文:https://blog.csdn.net/qq_34688380/article/details/78645126 
版权声明:本文为博主原创文章,转载请附上博文连接!app

三、安装Nginxtcp

#yum update
更新一些库和必要的支持,完了以后去下载一个nginx的最新版,现在我责编的版本是1.7.7:
#wget http://nginx.org/download/nginx-1.13.6.tar.gz
解压缩
#tar -zvxf nginx-1.13.6.tar.gz
#cd nginx-1.13.6
nginx有不少不少编译配置项,但因为我这是第一篇笔记,因此我基本上都使用了默认的配置:
#./configure --with-http_ssl_module --with-http_gzip_static_module
我只加了两个选项,--with-http_ssl_module表示使用ssl模块,--with-http_gzip_static_module表示使用gzip模块,其它更详细的配置就要参考nginx的文档了:http://nginx.org/en/docs/configure.htmlui

若是没configure成功(会显示XXX not found),那是由于有些依赖没有被正确安装.那么先安装一下这些依赖条件,一般是pcre,zlib这些,这么一下就基本上能够了:
#yum install gcc pcre pcre-devel zlib zlib-devel openssl openssl-develspa

#make
#make install

可执行文件就会被安装在: /usr/sbin/nginx (默认配置)

 

nginx基本使用

程序位置:/usr/local/nginx/sbin/nginx 

配置文件位置:/usr/local/nginx/conf/nginx.conf

 

启动nginx:
#cd /usr/local/nginx/sbin/
#./nginx

若是运行的时候不带-c参数,那就采用默认的配置文件,即/etc/nginx/nginx.conf

查看运行进程状态:
# ps aux | grep nginx

打开浏览器,访问http://localhost/看看nginx的默认页面:

中止nginx:
#./nginx -s stop

重启nginx(配置文件变更后须要重启才能生效):
#./nginx -s reload

检查配置文件是否正确:
#./nginx -t

查看nginx的pid:
cat /usr/local/nginx/logs/nginx.pid

查看nginx版本
$ ./nginx -v

回头看编译配置
# ./nginx -V

四、Nginx配置

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

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    upstream xxx.abc.com{
        ip_hash;
        server xxx1.abc.com;
        server xxx2.abc.com:8989;
    }
	
    server {
        listen       80;
        server_name  127.0.0.1;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
			proxy_pass http://xxx.abc.com;
            root   html;
            index  index.html index.htm;
        }

        #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;
        #}
    }
	
	server {
        listen       6010;
        server_name  127.0.0.1;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
			proxy_pass http://xxx.abc.com;
            root   html;
            index  index.html index.htm;
        }

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


    # 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;
        server_name  127.0.0.1;
        ssl on;
        ssl_certificate      1565150__abc.com.pem;
        ssl_certificate_key  1565150__abc.com.key;

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

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

        location / {
			proxy_pass https://xxx.abc.com;
            root   html;
            index  index.html index.htm;
        }
    }

}

参考:https://www.cnblogs.com/xiaoruilin/p/7782214.html

相关文章
相关标签/搜索