Nginx安装和反向代理供应
Nginx的安装需要一些准备工作。安装gcc等。
yum -y install make zlib zlib-devel gcc-c libtool openssl openssl-devel还必须安装Pcre(Perl兼容的正则表达式),它是一个Perl库,包含Perl兼容的正则表达式库。
下载Nginx源码包,这里选的是1.7.8版本。压缩包被解压缩,程序被编译
程序编译成功后,到Nginx文件目录查询下一个版本,验证是否安装。
[root@ACtest ~]# cd /usr/local/nginx/sbin/ [root@ACtest sbin]#/usr/local/nginx/sbin/nginx //起动Nginx [root@ACtest sbin]# ./nginx -v //认证下Nginx版本 nginx version: nginx/1.7.8 [root@chumjtest sbin]# ps aux|grep nginx //查询下Nginx起动过程 root 4684 0.0 0.0 103256 840 pts/1 S 15:14 0:00 grep nginx root 32670 0.0 0.0 24304 700 ? Ss Dec23 0:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf nobody 32671 0.0 0.0 26804 3824 ? S Dec23 0:00 nginx: worker process nobody 32672 0.0 0.0 26748 3396 ? S Dec23 0:16 nginx: worker process安装后装备Nginx。
[root@ACtest ~]#cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak //将主环境变量开展备份数据 [root@ACtest ~]#vim /usr/local/nginx/conf/nginx.conf //这儿将原先的环境变量清除,更换新的环境变量。 user nobody nobody; worker_processes 2; error_log /usr/local/nginx/logs/nginx_error.log crit; pid /usr/local/nginx/logs/nginx.pid; worker_rlimit_nofile 51200; events { use epoll; worker_connections 6000; } http { include mime.types; default_type application/octet-stream; server_names_hash_bucket_size 3526; server_names_hash_max_size 4096; log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]' '$host "$request_uri" $status' '"$http_referer" "$http_user_agent"'; sendfile on; tcp_nopush on; keepalive_timeout 30; client_header_timeout 3M; client_body_timeout 3M; send_timeout 3M; connection_pool_size 256; client_header_buffer_size 1k; large_client_header_buffers 8 4k; request_pool_size 4k; output_buffers 4 32k; postpone_output 1460; client_max_body_size 十米; client_body_buffer_size 258k; client_body_temp_path /usr/local/nginx/client_body_temp; proxy_temp_path /usr/local/nginx/proxy_temp; fastcgi_temp_path /usr/local/nginx/fastcgi_temp; fastcgi_intercept_errors on; tcp_nodelay on; gzip on; gzip_min_length 1k; gzip_buffers 4 9k; gzip_comp_level 5; gzip_http_version 1.1; gzip_types text/plain application/x-javascript text/css text/htm application/xml; }重启nginx并终止Nginx进程
配备反向代理
根据nginx浏览不同的web服务器端口号
例如:localhost:9080=10.1.1.78:9080
添加环境变量
server { listen 9080; //代理商的端口号 server_name localhost; //该设备的信息内容 location / { proxy_pass http://10.1.1.78:9080/; //表明代理商的详细地址 proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } # access_log /home/logs/bb_access.log combined; }装备好之后,重启Nginx。过会儿检查它。
[root@ACtest sbin]# curl -I http://localhost:9080 HTTP/1.1 200 OK Server: nginx/1.7.8 Date: Mon, 26 Dec 2016 07:52:37 GMT Content-Type: text/html Content-Length: 1812 Connection: keep-alive Last-Modified: Tue, 14 Jun 2016 01:53:30 GMT ETag: "714-53533459b292a" Accept-Ranges: bytes检测成功表明网站可以正常浏览。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)