`

nginx:vhost

阅读更多
nginx配置多个vhost
1.进入配置安装目录 cd /usr/local/etc/nginx/conf/
2.没有vhost文件夹 mkdir vhsot文件
3.添加多个conf文件 如:test.com.conf test1.com.conf
4.test.com.conf
  server {
    listen          80;       
    server_name     test.com;       
    index           index.html index.htm index.php;       
    root            /Users/suncg/www/test.com;        
    log_format      test.com '$remote_addr - $remote_user [$time_local] $request' '$status $body_bytes_sent $http_referer' '$http_user_agent $http_x_forwarded_for';       
    access_log      /var/log/test.com.log test.com;
}

test1.com.conf
server {
    listen          80;       
    server_name     test1.com;       
    index           index.html index.htm index.php;       
    root            /Users/suncg/www/test1.com;        
    log_format      test1.com '$remote_addr - $remote_user [$time_local] $request' '$status $body_bytes_sent $http_referer' '$http_user_agent $http_x_forwarded_for';       
    access_log      /var/log/test1.com.log test1.com;
}
5.在/Users/suncg/www/  mkdir test.com 和 mkdir test1.com 以及在响应文件夹下创建 index.html 内容为1111 和 2222
6.在/usr/local/conf/nginx.conf http{}部分添加include       vhost/*.conf;
如:
http
{
      #include       conf/mime.types;
      include       mime.types;
      default_type  application/octet-stream;
      include       vhost/*.conf;

      keepalive_timeout 120;

      tcp_nodelay on;

      upstream  www.samson.com  {
              server   127.0.0.1:8080;
              # server   192.168.1.3:80;
              # server   192.168.1.4:80;
              # server   192.168.1.5:80;
      }

      server
      {
              listen  80;
              server_name  www.samson.com;

              location / {
                       proxy_pass        http://www.samson.com;
                       proxy_set_header   Host             $host;
                       proxy_set_header   X-Real-IP        $remote_addr;
                       proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
              }

              log_format  www_samson_com  '$remote_addr - $remote_user [$time_local] $request '
                                '"$status" $body_bytes_sent "$http_referer" '
                                '"$http_user_agent" "$http_x_forwarded_for"';
              access_log  logs/www.log  www_samson_com;
      }

}

配置host
127.0.0.1  test.com
127.0.0.1  test1.com
访问test.com 显示1111 访问test1.com显示2222
分享到:
评论

相关推荐

    nginx-vhost:用于生成 vhost 目录的 Shell 脚本

    Nginx Vhost 项目的存在是为了提供一个简单的 shell 脚本来生成一个 vhost 目录。 这个项目是在 Ubuntu 服务器上构建的,可能不适用于其他平台。 为获得最佳效果,我们建议: Ubuntu 10.10 (Maverick) 取决于: ...

    ansible-nginx-vhost:角色扮演

    Nginx虚拟主机为Nginx配置一个虚拟主机要求Nginx应该已经安装在系统上(可以通过Firehed.nginx角色来完成)角色变量必需的: vhost_index: index.phpvhost_root: /var/www/example.comvhost_name: example.com可选的...

    nginx: [warn] "log_format" directive used only on "http" level 解决方法

    确保在包含虚拟主机配置文件(如`include vhost/*.conf`)之前定义`log_format`,否则Nginx将无法识别在`access_log`指令中引用的`Main`格式。 这样做有几个好处: - **集中管理**:所有的日志格式定义都在一个地方...

    nginx-vhost-conf.zip_nginx_nginx虚拟机配置

    在`nginx-vhost-conf.zip`中,`www.test.net.conf`就是一个具体的虚拟主机配置示例。通过编辑这个文件,我们可以为`www.test.net`这个域名设置特定的服务器行为。 ### 2. 配置文件结构 一个基本的Nginx虚拟主机...

    pp-nginx:用于木偶的纤薄但功能强大的Nginx模块

    $ cd modules$ git clone https://github.com/DracoBlue/pp-nginx.git nginx用法例子# include package and server for nginxinclude nginx$server = "example.org"# define new server (/vhost)nginx :: server { $...

    nginx-vhost-bak.conf

    NGINX支持HTTP和HTTPS协议的配置,同时开启了TLSv1.3。为了避免重新安装NGINX服务器时找不到已经调整差不多的配置信息,特地将此备份。

    Nginx转发到动态域名的proxy.conf

    Nginx在vhost里的配置站点,通过proxy转发到动态域名的具体配置。 反向代理,动态域名 ,Proxy

    nginx-vhost-creator

    nginx-vhost-creator nginx vhost 创建者脚本的使用: 以root用户或有权编辑nginx配置文件和修改权限的用户登录,即可访问web根目录。 使用 php-cli 执行 php 脚本 - 例如: ...

    nginx: [warn] “log_format” directive used only on “http” level 解决方法

    将nginx升级到1.2.4稳定版之后,会发现之前的vhost/*.conf中的日志配置都报了如下的warn: 代码如下: nginx: [warn] the “log_format” directive may be used only on “http” level 上网搜索解决方案如下: 将/...

    passenger_nginx_vhost_test:练习和测试passenger_nginx_vhost LWRP的食谱

    passenger_nginx_vhost_test 这是一个简单的食谱设计测试passenger_nginx_vhost其通过暴露LWRP passenger_nginx食谱。 要运行 ChefSpec 测试,只需运行: rspec -fd --color 要运行 ServerSpec 测试(通过 ...

    Nginx 配置多站点vhost 的方法

    * vhost:虚拟主机,指的是在同一个服务器上托管多个网站的技术。Nginx 支持配置多个 vhost,每个 vhost 对应一个站点。 * server_name:指定站点的服务器名称,例如 `www.ushark.net`。 * root:指定站点的根目录,...

    nginx-vhost-admin

    Nginx服务器管理员 Nginx服务器管理员是一个简单的应用程序,可帮助您在nginx安装上创建和编辑虚拟主机。将其部署在所有服务器上,并用于管理数据。 安装 拉码 运行npm install或yarn 在config/local.js编辑配置,将...

    bw.bundle.nginx:通过Bundlewrap在Debian或CentOS上安装Nginx

    Bundlewrap Nginx 在Debian,Amazon Linux或CentO上安装nginx并配置vHost。 不要将其用于生产! 仍在进行中!选项'nginx' : { 'enable_websockets' : False , 'resolver' : [ '1.1.1.1' , '1.0.0.1' , '[2606:4700:...

    linux搭建nginx WEB服务器的教程.docx

    10. 多站点设置:创建 vhost 目录,编辑 linlik.conf 文件,并在 nginx.conf 文件中 include vhost 目录下的配置文件。 11. 站点配置文件内容:编辑 linlik.conf 文件,添加 server 块,配置监听端口、服务器名称、...

    ubuntu+nginx安装配置应用说明

    在本文中,我们将深入探讨如何在Ubuntu操作系统上安装和配置Nginx服务器,这是一个流行的开源Web服务器,以其高性能和稳定性而闻名。Nginx广泛用于处理静态内容、反向代理和负载均衡等任务。 首先,确保你的Ubuntu...

    nginx配置虚拟主机vhost的方法详解

    - 在Nginx的配置目录下(如 `/etc/nginx` 或 `/opt/nginx/conf`),创建一个子目录,比如 `vhosts`,用于存放各个虚拟主机的配置文件。 - 每个虚拟主机对应一个单独的配置文件,例如 `www.domain.com.conf`。 2. ...

    国产化环境麒麟v10系统arm64下安装nginx所有依赖

    5. **ngx_http_vhost_traffic_status_module**:这是一个可选的Nginx模块,用于监控每个虚拟主机的流量状态。如果需要,可以手动下载源代码并编译安装。 6. **其他可选模块**:根据需求,可能还需要安装其他第三方...

    Nginx之配置虚拟主机vhost

    当一台服务器上,需要使用nginx部署多套项目时,将所有项目配置在同一config 下,容易出现混乱,维护起来也比较困难。 部署多项目时,因为每个项目启动都会有不一样的端口号,客户端请求的时候需要带相应端口号,...

    nginx配置多个虚拟主机vhost的方法示例

    在nginx下配置虚拟主机vhost非常方便。主要在nginx的配置文件nginx.conf中添加一个server即可 比如我想配置两个虚拟主机,通过域名linux.com和linux2.com访问,分别对应的目录是/usr/htdocs/linux 和/usr/htdocs/...

Global site tag (gtag.js) - Google Analytics