zoukankan      html  css  js  c++  java
  • nginx入门一

    配置文件:

    server_name

    user  root;
    worker_processes  2;
    
    error_log  logs/error-test.log;
    #pid        logs/nginx.pid;
    
    
    events {
        worker_connections  1024;
    }
    
    
    http {
        include       mime.types;
        default_type  application/octet-stream;
    
    
        sendfile        on;
    
        server {
            listen       80;
    	return  405;
        }
    
    
    }
    

     表示没有设置Host字段的请求都返回405,也可以写一个非标码(444)表示关闭连接。

    添加虚拟主机:

    ...    
    server {	
            listen       80;
    	server_name  www.ngx1.com;
    	
    	location / {
    		root html;
    		index ngx1.html;
    	}
        }
    
        server {	
            listen       80;
    	server_name  www.ngx2.com;
    	
    	location / {
    		root html;
    		index ngx2.html;
    	}
        }
    ...
    

     当然,需要修改hosts文件:

    添加:

    127.0.0.1	www.ngx1.com
    127.0.0.1	www.ngx2.com
    

     html/下新建ngx1.html,ngx2.html

    浏览器测试:

    http://192.168.2.192/

    405 Not Allowed

    http://www.ngx1.com/

    hello it's www.ngx1.com

    http://www.ngx2.com/

    hello it's www.ngx2.com

    server_name 还支持,通配符,正则匹配:

    比如:*.example.com , www.example.*

    ~^www.example.com$ ,

     dafault_server是默认的,如果其他的都不能匹配就用dafault_server处理,一般返回404,405...

     

    location

    location :重定向,可以嵌套使用,正则

    ~:区分大小写,~*:不区分大小写

    当所有请求转发到一台服务器的时候(比如uwsgi),但是其中图片,视频在nginx下,所以就要过滤

    	# 指定项目路径uwsgi
    	location / { # 这个location就和咱们Django的url(r'^admin/', admin.site.urls),
    	include uwsgi_params; # 导入一个Nginx模块他是用来和uWSGI进行通讯的
    	uwsgi_connect_timeout 30; # 设置连接uWSGI超时时间
    	uwsgi_pass unix:/root/GitClient/script/touchrnb.sock; # 指定uwsgi的sock文件所有动态请求就会直接丢给他
    	}
    
    	# 指定静态文件路径
    	location /static/ {
    	alias /root/GitClient/touch/static_all/;
    	index index.html index.htm;
    	}
    
            location /uwsgi_http/{
    
                proxy_pass http://127.0.0.1:8080/;
    
            }
    
            location /vods/{
    
            }
    
            location /images/{
    
            }
    
  • 相关阅读:
    JavaScript的3种继承方式
    JavaScript回调函数及数组方法测试
    JavaScript实现二叉树算法
    SpringMVC之使用Servlet原生API作为参数
    HashMap详解
    面试笔记--Fast-Fail(快速失败)机制
    面试笔记--HashMap扩容机制
    org.yaml.snakeyaml.error.YAMLException: java.nio.charset.MalformedInputException: Input length = 1
    多模块调用Service失败
    常用命令汇总
  • 原文地址:https://www.cnblogs.com/lanqie/p/7921473.html
Copyright © 2011-2022 走看看