将域名与本地地址建立映射关系(IIS与nginx)

1、IIS映射

1.1、修改hosts文件

示例:将域名www.abc.com映射到127.0.0.1

// 方式:通过修改hosts文件
C:\Windows\System32\drivers\etc

如果修改host文件时,提示无权限,则需要到【属性】中的【安全】中的【高级】进行配置。

// 修改示例
  127.0.0.1   www.abc.com

1.2、验证代理效果

浏览器中输入域名,访问效果如下:
IIS代理后访问域名的效果

2、nginx

2.1、nginx的下载

下载地址:https://nginx.org/en/download.html 或者搜索nginx官网。在下载版本中优先选择稳定版。
nginx下载版本界面

2.2、nginx安装

将下载的安装包放在电脑任意盘的某个位置解压。然后点击nginx.exe启动,或者在nginx文件夹中启用cmd进行命令启动。
启动后可以在任务管理器中查看到nginx.exe(32位)
任务管理器中验证nginx是否启动

2.3 修改配置表

配置文件地址:nginx文件的conf文件夹中的nginx.conf。用记事本打开。
一个server就是一个代理

// Server部分的简单介绍
server {
    listen  80;  
    //监听端口为80,可以自定义其他端口,也可以加上IP地址。如:listen 127.0.0.1:8080;
    server_name  localhost; 
    //定义网站域名,可以写多个,用空格分隔。
    #charset koi8-r; 
    //定义网站的字符集,一般不设置,而是在网页代码中设置。
    #access_log  logs/host.access.log  main; 
    //定义访问日志,可以针对每一个server(即每一个站点)设置它们自己的访问日志。

    ##在server{}里有很多location配置段
    location / {
        root   html;  //定义网站根目录,目录可以是相对路径也可以是绝对路径。
        index  index.html index.htm; //定义站点的默认页。
    }

    #error_page  404              /404.html;  //定义404页面

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;  //当状态码为500、502、503、504时,则访问50x.html
    location = /50x.html {
        root   html;  //定义50x.html所在路径
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #定义访问php脚本时,将会执行本location{}部分指令
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;  //proxy_pass后面指定要访问的url链接,用proxy_pass实现代理。
    #}

    # 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服务器监听端口与地址,支持两种形式,1 IP:Port, 2 unix:/path/to/sockt
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;  //定义SCRIPT_FILENAME变量,后面的路径/scripts为上面的root指定的目录
    #    include        fastcgi_params; //引用prefix/conf/fastcgi_params文件,该文件定义了fastcgi相关的变量
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    # 
    #location ~ /\.ht {   //访问的url中,以/.ht开头的,如,www.example.com/.htaccess,会被拒绝,返回403状态码。
    #    deny  all;  //这里的all指的是所有的请求。
    #}
}

# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
#    listen       8000;  //监听8000端口
#    listen       somename:8080;  //指定ip:port
#    server_name  somename  alias  another.alias;  //指定多个server_name

#    location / {
#        root   html;
#        index  index.html index.htm;
#    }
#}

# HTTPS server
#
#server {
#    listen       443 ssl;  //监听443端口,即ssl
#    server_name  localhost;

### 以下为ssl相关配置
#    ssl_certificate      cert.pem;    //指定pem文件路径
#    ssl_certificate_key  cert.key;  //指定key文件路径

#    ssl_session_cache    shared:SSL:1m;  //指定session cache大小
#    ssl_session_timeout  5m;  //指定session超时时间
#    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;   //指定ssl协议
#    ssl_ciphers  HIGH:!aNULL:!MD5;  //指定ssl算法
#    ssl_prefer_server_ciphers  on;  //优先采取服务器算法
#    location / {
#        root   html;
#        index  index.html index.htm;
#    }
#}

下面给出一个自定义代理的server示例。

域名代理的server示例

2.4、重启nginx

nginx -s reload

2.5、验证代理

浏览器中输入域名访问。出现welcome to nginx
nginx的server代理域名成功后显示效果

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值