当前位置:小鱼儿玄机二站 > 计算机网络 > nginx虚构域名监听,nginx常用命令

nginx虚构域名监听,nginx常用命令

文章作者:计算机网络 上传时间:2019-12-03

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;
        }
    }
}

1.测验配置文件:nginx -t

2.起步命令:nginx

3.甘休命令:nginx -s stop或nginx -s quit

4.重启命令:nginx -s reload

5.翻看进程命令:ps -ef |grep nginx

设想域名配置及测量试验评释:

安顿步骤:

1.编辑nginx.conf

2.增加include vhost/*.conf

vhost配置文件解析:

server { 
    listen 80; 
    autoindex on; 
    server_name tomcat.imooc.com; 
    access_log c:/access.log combined; 
    index index.html index.htm index.jsp index.php; 
    #error_page 404 /404.html; 
    if ( $query_string ~* ".*[;'<>].*" ){ 
        return 404; 
    } 
    location / { 
        proxy_pass http://127.0.0.1:8080; 
        add_header Access-Control-Allow-Origin *; 
    } 
}

listen 80:监听80端口

autoindex on:是或不是自动创设首页索引目录

server_name tomcat.imooc.com:二级域名,当nginx接到这种须要,会透过proxy_pass,将以此域名央求改变成

proxy_pass:转移到的真正域名,这里也能够用root + 本地存放地方目录。

ngnix本地的注意事项:

1.方可安顿域名转发,但必然要安顿host(如果不安排host,用的域名正是真实域名,不会生效),並且使host生效之后才足以,设置实现之后要重启浏览器。

 配置host步骤:

  1)进入C:WindowsSystem32driversetc

  2)用记事本展开hosts文件

  3)加多好对应的域名及ip

 

本文由小鱼儿玄机二站发布于计算机网络,转载请注明出处:nginx虚构域名监听,nginx常用命令

关键词: