澳门新萄京官方网站-www.8455.com-澳门新萄京赌场网址

用Nginx配置虚拟域名,nginx服务器配置多域名

2019-06-01 作者:服务器运维   |   浏览(144)

nginx——虚拟域名与多端口监听及其配置,nginx虚拟域名监听

nginx的配置

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       82;
        server_name  localhost;
        root D:/cardLoan/tuandai-loans/loans-web-admin/src/main/resources/web;
        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root D:/cardLoan/tuandai-loans/loans-web-admin/src/main/resources/web;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        #error_page   500 502 503 504  /50x.html;
        #location = /50x.html {
        #    alias   E:/aaa2
        #}

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ .php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # 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_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

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


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

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


    server {
        listen       80;
        server_name  dq.aaa.cn;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {
                proxy_pass    http://10.100.66.255:9007;
                proxy_redirect default ;              

        } 
      }

    #server {
        #listen       80;
        #server_name  www.aaa.cn;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        #location / {
                #proxy_pass    http://127.0.0.1:8081;
                #proxy_redirect default ;              

        #}
      #}

   server {
        listen       80;
        server_name  psjs.aaa.cn;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location /dq {
                alias   E:/psjs.aaa.cn-static/dq;
        #root   E:/td-sail-js;
                index  index.html index.htm;         

        } 
        location /scripts {
                alias   E:/psjs.aaa.cn-static/dq/scripts;
        }

        location /images {
                alias   E:/psjs.aaa.cn-static/dq/images;
        #root   E:/td-sail-js;
                index  index.html index.htm;         

        } 
      }

     server {
        listen       80;
        server_name  js2.aaa.cn;
        #root E:/aaa2/js.aaa.cn;
        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   E:/psjs.aaa.cn-static;
            index  index.html index.htm;
        }
    location /images {
            alias   E:/psjs.aaa.cn-static/images;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        #error_page   500 502 503 504  /50x.html;
        #location = /50x.html {
        #    alias   E:/aaa2
        #}

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ .php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # 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_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /.ht {
        #    deny  all;
        #}
    }
}

MP的配备格局
nginx.conf

# 常用命令
# 启动: nginx
# 重启: nginx -s reload
# 关闭: nginx -s stop

# 1 域名 端口 唯一确定一个资源。 nginx 可以同时监听 多个虚拟域名 和 多个端口。可以做方向代理

# 用的帐号和组,windows的直接注释掉就好了
#user  benny staff;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    gzip on;
    gzip_min_length 1k;
    gzip_buffers 16 64k;
    gzip_http_version 1.1;
    gzip_comp_level 6;
    gzip_types text/plain application/x-javascript text/css application/xml application/javascript;
    gzip_vary on;

    # 当你访问localhost时的站点配置,地址默认是d:/wwwroot
    server {
        listen       90;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;


        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;

        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ .php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # 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_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /.ht {
        #    deny  all;
        #}
    }

    # include vhosts/*.conf; # 将vhosts所有东西包含进来
    include vhosts/cardloan.dev.com.conf;

    autoindex on; #开启nginx目录浏览功能
    autoindex_exact_size off; #文件大小从KB开始显示
    autoindex_localtime on; #显示文件修改时间为服务器本地时间


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

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


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

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

}

vhost.conf

# 想建一个新站点?
# 1、复制本文件然后改名
# 2、修改root值,指向你的新站点根目录
# 3、运行nginx -s reload 重新加载配置就行了
server {
    listen  82;
    server_name  cardload.dev.com;
    root   D:/cardLoan/tuandai-loans/loans-web-admin/src/main/resources/web;
    index  index.html index.htm;

    error_page   500 502 503 504  /50x.html;

    location ~ /.ht {
        deny  all;
    }
}

网络找的 如card.dev.com.conf

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on; 

    keepalive_timeout  65; 

    gzip  on;

    upstream localhost {
        server 127.0.0.1:8080 max_fails=7 fail_timeout=7s;
    }   
    server {
        listen       81; 
        server_name  localhost;
        location / { 
            root html;
            index index.html index.htm;
            proxy_pass http://localhost;
        }   
    }   
    server {
        listen       80; 
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / { 
            root   html;
            index  index.html index.htm;
            proxy_pass http://localhost;
        }
    }
}

nginx的安装:

nginx服务器支持配置多站点,大家得以透过配备子域名令你的3个域名下放置多少个档期的顺序。

nginx服务器协理配置多站点,大家能够透过计划子域名让您的二个域名下放置八个门类。

一.在nginx.conf加入以下:

用Nginx配置虚拟域名,nginx服务器配置多域名。nginx已安装完成的场合下,轻易的配置配置域名访问

那就是说怎么样兑现那么些过程吧?

那么哪些落到实处那几个进程吧?

server {

1、修改 - nginx/conf/nginx.conf文件

互连网上的浩大方案,某个写的过于繁杂,某个则是计划有误,大概说,某个配置项是要基于本身的主机实际条件来布局的。

互连网上的大多方案,有个别写的过分繁杂,有个别则是布置有误,或许说,有些配置项是要依据自个儿的主机实际条件来布署的。

#监听绑定80端口

在http { ... }中引入文件(一般情状下会有多少个域名,引进文件好扩充维护)

一.假令你的花色路径是投身 /home/wwwroot/路线下,nginx的设置路线是 /usr/local/nginx/ 目录下

壹.固然你的类型路径是坐落 /home/wwwroot/路线下,nginx的装置路线是 /usr/local/nginx/ 目录下

listen      8082;

如图,作者在路线D:/nginx/conf/ershuai下有广繁多的以.conf结尾的公文,每一个.conf文件都以一个域名配置;*意味着你的自由文件名称

二.设置好nginx都会有暗许的布置文件。文件路线为/usr/local/nginx/conf/nginx.conf

二.设置好nginx都会有暗中同意的配置文件。文件路径为/usr/local/nginx/conf/nginx.conf

#上边那个是域名,多个域名用空格隔断

图片 1

三.现在你须要将你的花色映射到四个域名下。首先查看nginx.conf文件最终1行,它代表include了目前vhost目录下的全体.conf文件。此时,假使尚未vhost文件大家得以创设那些文件夹。

叁.以往你须要将你的花色映射到多个域名下。首先查看nginx.conf文件最后一行,它代表include了当前vhost目录下的全数.conf文件。此时,若是尚未vhost文件我们得以创制这几个文件夹。

server_name  shangxinadmin.com;

二、配置D:/nginx/conf/ershuai下的域名文件;

                access_log  /home/wwwlogs/access.log  access;        }include vhost/*.conf;
                access_log  /home/wwwlogs/access.log  access;
        }
include vhost/*.conf;

#本网址的根路线

此间本身铺排贰个testsg.xxx.com的二级域名,域名能够有两个,以空格隔开(.conf文件名能够随便取,作者取的和域名同样是有益维护)

4.然后在vhost目录下新建三个您要求加上的域名配置文件,命名自定义。然后大家可现在里面增多内容。上面能够上课一下多少个实际的配备项目。

四.然后在vhost目录下新建一个你要求丰硕的域名配置文件,命名自定义。然后大家可未来里面增多内容。下边能够上课一下多少个有血有肉的安排项目(轻松的略过)。

root  "D:/phpStudy/WWW/project/WebServices/shangxinAdmin/public/";

listen 监听端口,service_name定义访问;location/proxy_pass 本地下工作程访问路线;

1.index index.html  index.php 表示默认的定位的文件,假如直接访问域名,会定位到index.html或者index.php文件
2.fastcgi_pass  这个命令是指定将http代理到哪个fastcgi服务端接口
3.fastcgi_index  该指令设置的文件会被附加到URI的后面并保存在变量$fastcgi_script_name中
4.fastcgi_param SCRIPT_FILENAME  脚本文件请求的路径
5.include  fastcgi_params;  包含fastcgi_params中的所有参数

server{        listen 80;        server_name www.news.com;        root /home/wwwroot/news/;        location /{                index index.html  index.php;        }        location ~ .php$ {            fastcgi_pass   127.0.0.1:9000;
        #fastcgi_pass  unix:/tmp/fastcgi.socket;            fastcgi_index  index.php;            fastcgi_param  SCRIPT_FILENAME      $document_root$fastcgi_script_name;            include    fastcgi_params;        }}
1.index index.html  index.php 表示默认的定位的文件,假如直接访问域名,会定位到index.html或者index.php文件
2.fastcgi_pass  这个命令是指定将http代理到哪个fastcgi服务端接口
3.fastcgi_index  该指令设置的文件会被附加到URI的后面并保存在变量$fastcgi_script_name中
4.fastcgi_param SCRIPT_FILENAME   脚本文件请求的路径 
5.include  fastcgi_params;  包含fastcgi_params中的所有参数

server{
        listen 80;
        server_name www.news.com;
        root /home/wwwroot/news/;
        location /{
                index index.html  index.php;
        }
        location ~ .php$ {
            fastcgi_pass   127.0.0.1:9000;
        #fastcgi_pass   unix:/tmp/fastcgi.socket;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME      $document_root$fastcgi_script_name;
            include    fastcgi_params;

        }
}

#上面是默许首页

service里面还会有为数相当多个性和正则等,稳步学习中…

5.假使大家是在本机测试,设置了虚拟域名今后,大家什么在融洽的linux主机上访问呢?

伍.假如大家是在本机测试,设置了虚拟域名自此,大家如何在自个儿的linux主机上访问呢?

location / {

图片 2

一.大家得以透过修改/etc/hosts来让域名映射到本人的主机上。比方作者前面定义的www.news.com

壹.咱们可以透过改动/etc/hosts来让域名映射到谐和的主机上。比方本人事先定义的www.news.com

index  index.html index.php;

三、以上配置实现,重启nginx,就足以通过testsg.xxx.com访问了

二.大家开发hosts文件,在背后增添 12柒.0.0.1 www.news.com

二.大家开发hosts文件,在后面加多 1二柒.0.0.壹 www.news.com

#下边那个能够兑现访问其安顿的虚拟域名下的门径,如:XXX.com/admin/index.php

图片 3

三.假若修改hosts文件恐怕不可能访问。那表达还亟需修改network文件。打开/etc/sysconfig/network文件,修改为NETWOKoleosKING=yes,然后service network restart,重启network

3.即便修改hosts文件或然不能访问。这表达还亟需修改network文件。展开/etc/sysconfig/network文件,修改为 NETWOLANDKING=yes,然后service network restart,重启network 

try_files $uri $uri/ /index.php?$query_string;

负载均衡 

 

}

#下边是针对性本站全部.php文件实行拍卖的配置

location ~ .php{

#加载fastcgi  一种管理格局

include fastcgi_params;

#fastcgi的参数 钦赐文件路线及参数,不然会有404或者file not find 提醒

fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;

#fastcgi的服务音信 ip:端口

fastcgi_pass 127.0.0.1:9000;

#fastcgi暗中认可首页

fastcgi_index index.php;

}

}

本文由澳门新萄京官方网站发布于服务器运维,转载请注明出处:用Nginx配置虚拟域名,nginx服务器配置多域名

关键词: