• 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/{
    
            }
    
  • 相关阅读:
    Mysql基础3-数据操作语言DML-数据查询语言DQL
    Mysql基础2-数据定义语言DDL
    Mysql基础1-基础语法-字段类型
    php源码建博客5--建库建表-配置文件-错误日志
    PHP基础4--函数-数组
    php源码建博客4--实现MVC结构微型框架
    PHP基础3--文件加载-错误处理
    php源码建博客3--区分平台的MVC结构
    php源码建博客2--实现单入口MVC结构
    php源码建博客1--搭建站点-实现登录页面
  • 原文地址:https://www.cnblogs.com/lanqie/p/7921473.html
Copyright © 2020-2023  润新知