Nginx域名配置和验证测试

配置nginx.conf方便管理域名

  1. 编辑conf/nginx.conf
  2. 增加一行 include vhost/*.conf;

好处是,以后在conf/vhost下新增对应域名的配置文件方便管理。如:xxx.com.conf。

指向(端口)配置说明

#主节点
server {
    linsten 80; # 监听端口
    autoindex on; # 是否创建首页索引目录
    server_name xxxx.com # 将这个域名下的请求转发到location配置
    access_log /use/local/nginx/logs/access.log combined; # nginx访问日志
    index index.html index.htm index.jsp index.php; # 输入页面默认的首页顺序
    error_page 404 /404.html; # 错误跳转页面

    location / {
        proxy_pass xxxx.com; # 需要转移到的地址
        add_header Access-Control-Allow-Origin *;
    }
}

指向(目录)配置说明

#主节点
server {
    linsten 80; # 监听端口
    autoindex on; # 是否创建首页索引目录
    server_name img.xxxx.com # 将这个域名下的请求转发到location配置
    access_log /use/local/nginx/logs/access.log combined; # nginx访问日志
    index index.html index.htm index.jsp index.php; # 输入页面默认的首页顺序
    error_page 404 /404.html; # 错误跳转页面

    location / {
        root /product/xxx/img/; # 需要转移到的资源路径
        add_header Access-Control-Allow-Origin *;
    }
}

Nginx本地玩耍测试注意

  • 配置域名转发,一定要配置host,使host生效后,就可以使用虚拟域名进行测试了。
  1. Linux:
    1. sudo vim /etc/hosts
    2. 添加好对应的域名及ip
  2. Windows:
    1. 进入 C:\Windows\System32\drivers\etc
    2. 记事本打开hosts文件,添加对应的ip和域名,格式192.168.1.1 www.xxx.com; 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值