首页 > 编程知识 正文

虚拟机怎么改网关和ip,python 虚拟主机

时间:2023-05-03 18:57:39 阅读:115887 作者:1615

Nginx默认虚拟主机定义默认虚拟主机配置文件,并在http下添加include vhost/*.conf

在/usr/local/nginx/conf/下创建目录

#创建#mkdirvhost//vhost目录

#进入#cd vhost///目录

#编辑#vim aaa.com.conf //文件

服务器

{

listen 80 default_server; //标有此标记的是默认虚拟主机

server_name aaa.com;

index index.htmlindex.htm index.PHP;

根/数据/万维网/默认值;

}

#创建#mkdir /data/wwwroot/default //目录

# echo“thisisadefaultsite .”/data/www root/default/index.html

#/usr/local/nginx/sbin/nginx-t//检测语句是否正确

//usr/local/nginx/sbin/nginx-s重新加载//nginx

#curl-x127.0.0.1:80AAA.com//测试

Nginx用户认证

# vim/usr/local/nginx/conf/vhost/test.com.conf /写入如下

服务器

{

listen 80

server_name test.com;

index index.htmlindex.htm index.PHP;

root /data/wwwroot/test.com;

位置/

{

auth_basic 'Auth ';

auth _ basic _ user _ file/usr/local/nginx/conf/htpasswd; //密码所在位置的文件

}

}

htpasswd是一种apache工具,主要用于创建和更新存储用户名和密码的文本文件,主要用于验证基于http的用户。 htpasswd安装很简单,是随apache安装一起生成的。

#yuminstall-yhttpd//httpd软件包下载

#生成htpasswd-c/usr/local/nginx/conf/htpasswdzenwen//密码文件

//usr/local/nginx/sbin/nginx-t-s reload//测试并重新加载配置

#创建#mkdir /data/wwwroot/test.com //目录

# echo“test.com”/data/www root/test.com/index.html

# curl-x 127.0.1336080 test.com-I//状态代码为401表示需要验证

# Curl-uz Enwen : passwd-x 127.0.1:80 test.com-I///访问状态代码为200

目录的用户验证

访问管理员时,只需将管理员目录添加到位置/即可对管理员进行用户验证

位置/管理员/

{

auth_basic 'Auth ';

auth _ basic _ user _ file/usr/local/nginx/conf/htpasswd;

}

nginx域名重定向

更改test.com.conf

服务器{

listen 80

server _ name test.com test1.com test2.com;

index index.htmlindex.htm index.PHP;

root /data/wwwroot/test.com;

if ($host!='test.com ' ) {

Rewrite^/(.* ) $ http://test.com/$1 permanent;

}

}

server_name后面支持写入多个域名。 这里与httpd进行比较

permanent是永久重定向,状态代码为301,写redirect为302

#/usr/local/nginx/sbin/nginx-t//检测语法

//usr/local/nginx/sbin/nginx-s重新加载//重新加载

# curl-x 127.0.1336080 test2.com/index.html-I///测试

http/1.1 301移动性能

Server: nginx/1.12.1

Date: Wed,03 Jan 2018 02:45:07 GMT

内容类型:文本/html

内容长度: 185

连接: keep-alive

已重定向至location :http://test.com/index.html//直接test.com

# curl-x 127.0.1336080 test1.com/index.html-I//显示状态代码为301

http/1.1 301移动性能

Server: nginx/1.12.1

Date: Wed,03 Jan 2018 06:53:13 GMT

内容类型:文本/html

内容长度: 185

连接: keep-alive

location :http://test.com/index.html

您可能也喜欢以下有关Nginx的文章,请参考:

Nginx详细介绍:请单击此处

Nginx下载地址:请单击此处

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。