如何设置Nginx反向绑定域名

上传人:mg****2 文档编号:122816110 上传时间:2020-03-07 格式:DOC 页数:17 大小:195.50KB
返回 下载 相关 举报
如何设置Nginx反向绑定域名_第1页
第1页 / 共17页
如何设置Nginx反向绑定域名_第2页
第2页 / 共17页
如何设置Nginx反向绑定域名_第3页
第3页 / 共17页
如何设置Nginx反向绑定域名_第4页
第4页 / 共17页
如何设置Nginx反向绑定域名_第5页
第5页 / 共17页
点击查看更多>>
资源描述

《如何设置Nginx反向绑定域名》由会员分享,可在线阅读,更多相关《如何设置Nginx反向绑定域名(17页珍藏版)》请在金锄头文库上搜索。

1、.如何设置Nginx反向绑定域名反向绑定域名,即将域名B绑定到域名A上,用户只要访问B就等同于进入A,内容都是由A提供,它有点像建立了一个A的镜像。什么时候要用到反向绑定域名?服务器集群和网站负载均衡时,把用户访问请求发送不同的服务器上。关于反向绑定域名的方法部落之前也分享过好几次,本篇文章就来详细介绍一下Nginx反向绑定域名方法。之所以要用Nginx,主要在于Nginx在反向绑定域名有着天然的优势,并且功能强大,可以满足我们更多更高的应用需求。平常我们都是用Nginx反向绑定域名来搞定无法绑定域名的空间,这次来分享一下搞定Google和Gravatar两个网站访问的问题,更多的有关于反向绑

2、定域名的方法还有: 多种应用:反向绑定域名的方法-强制绑定域名,实现负载均衡,域名内网转发; 简单操作:反向绑定域名方法-Nginx反向配置和kangle服务器反向设置; 虚拟主机:7ghost基于PHP的网站反向绑定域名程序无需.htaccess的URL重写。注意:上面提到的Nginx反向绑定域名都需要用到VPS主机,如果你只有虚拟主机,则可以试试7ghost。Nginx反向绑定域名方法和详细操作应用实例:Google和Gravatar一、Nginx安装和基本操作命令1、Nginx可以直接使用LNMP这样的一键安装包,例如:LNMP新版VPS主机控制面板安装。2、如果你是用一个专门的服务器来

3、作反向绑定域名用,则只需要安装一个Nginx即可,为VPS主要省点资源。命令: wget http:/sysoev.ru/nginx/nginx-0.7.64.tar.gz tar zxvf nginx-0.7.64.tar.gz cd nginx-0.7.64 ./configure -user=www -group=www -prefix=/usr/local/nginx -with-http_stub_status_module -with-http_ssl_module -with-ipv6 make & make install3、如果在执行以上命令遇到./configure: er

4、ror: the HTTP rewrite module requires the PCRE library.错误提示,运行:yum -y install pcre-devel openssl openssl-devel4、执行以下命令,把ngx_http_substitutions_filter_module模块编译进去,主要为了反向绑定域名过滤到页面的URL地址。 git clone https:/ ./configure -prefix=/usr/local/nginx -with-http_stub_status_module -with-http_ssl_module -with-h

5、ttp_gzip_static_module -with-ipv6 -add-module=/root/nginx-0.7.64/ngx_http_substitutions_filter_module make & make install5、最后添加www用户,启动Nginx服务。 /usr/sbin/groupadd -f www /usr/sbin/useradd -g www www /usr/local/nginx/sbin/nginx6、或者,你也可以直接使用以下命令: cd /tmp git clone git:/ # nginx 的过滤器模块(比http_sub_module

6、更加灵活) wget http:/nginx.org/download/nginx-1.7.7.tar.gz tar -xzvf nginx-1.7.7.tar.gz cd /tmp/nginx-1.7.7 ./configure -prefix=/www/wdlinux/nginx # 安装位置 -with-http_ssl_module -with-http_sub_module -with-http_gzip_static_module -with-http_stub_status_module -add-module=/tmp/ngx_http_substitutions_filter

7、_module # 添加nginx过滤器模块 make & make install7、Nginx的配置文件一般是在:/usr/local/nginx/conf 这个目录下nginx.conf。8、修改了nginx.conf文件后,记得先检测一下语法是否正常:/usr/local/nginx/sbin/nginx -t,防止重启Nginx后服务器不正常。9、Nginx重启命令:/usr/local/nginx/sbin/nginx -s reload 或者 kill -HUP cat /usr/local/nginx/logs/nginx.pid 或者 service nginx resatr

8、t10、上面介绍的两种安装方法适合有一定VPS经验的朋友,这里还有一个适合新手朋友的安装命令: yum -y install gcc automake autoconf libtool make yum install gcc gcc-c+ cd /usr/local/src wget ftp:/ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.34.tar.gz tar -zxvf pcre-8.34.tar.gz cd pcre-8.34 ./configure make make install cd /usr/local/sr

9、c wget http:/ tar -zxvf zlib-1.2.8.tar.gz cd zlib-1.2.8 ./configure make make install cd /usr/local/src wget http:/www.openssl.org/source/openssl-1.0.1c.tar.gz tar -zxvf openssl-1.0.1c.tar.gz cd /usr/local/src wget http:/nginx.org/download/nginx-1.4.2.tar.gz tar -zxvf nginx-1.4.2.tar.gz cd nginx-1.4

10、.2 git clone https:/ ./configure -sbin-path=/usr/local/nginx/nginx -conf-path=/usr/local/nginx/nginx.conf -pid-path=/usr/local/nginx/nginx.pid -with-http_ssl_module -with-http_sub_module -with-http_gzip_static_module -with-http_stub_status_module -with-pcre=/usr/local/src/pcre-8.34 -with-zlib=/usr/l

11、ocal/src/zlib-1.2.8 -add-module=/usr/local/src/nginx-1.4.2/ngx_http_substitutions_filter_module -with-openssl=/usr/local/src/openssl-1.0.1c make make install /usr/local/nginx/nginx server listen 80; server_name ; location / proxy_pass http:/ proxy_redirect off; proxy_set_header X-Real-IP $remote_add

12、r; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 2、你只需要修改server_name和proxy_pass的值即可。保存nginx.conf,重启Nginx,打开你的域名,就可以看到反向的效果了。3、如果想要反向绑定百度,直接把域名修改为百度的域名。4、然后打开自己的域名,就可以看到是百度了。三、Nginx反向绑定域名:带SSL证书1、为了能够保证自己反向绑定的“安全”,一般建议使用SSL证书。SSL证书现在购买也不是很贵,参考:Namecheap SSL证书购买和SSL激活安装使用方法和新Godaddy Cpa

13、nel主机安装Godaddy SSL证书方法。2、Nginx使用SSL进行反向绑定域名,修改nginx.conf如下: server listen 80; server_name ; location / rewrite /(.*)$ https:/$1 permanent; server listen 443; server_name ; if ($host = ) rewrite /(.*)$ https:/$1 permanent; ssl on; ssl_certificate /root/myssl/myssl.crt; ssl_certificate_key /root/myssl/privkey.key; location / proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https; proxy_pass https:/; proxy_set_he

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 教学/培训

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号