我是靠谱客的博主 仁爱白云,这篇文章主要介绍Nginx域名配置和验证测试,现在分享给大家,希望可以做个参考。

配置nginx.conf方便管理域名

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

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

指向(端口)配置说明

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
#主节点 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 *; } }

指向(目录)配置说明

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
#主节点 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:WindowsSystem32driversetc
    2. 记事本打开hosts文件,添加对应的ip和域名,格式192.168.1.1 www.xxx.com; 

最后

以上就是仁爱白云最近收集整理的关于Nginx域名配置和验证测试的全部内容,更多相关Nginx域名配置和验证测试内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(65)

评论列表共有 0 条评论

立即
投稿
返回
顶部