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/{

        }

 

转载于:https://www.cnblogs.com/lanqie/p/7921473.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值