当前位置首页 > Nginx知识

nginx入门一

阅读次数:265 次  来源:admin  发布时间:

erver_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.1www.ngx1.com
127.0.0.1www.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

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

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

~^www\.example\.com$ ,

nginx入门一

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

locatio

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

        }
上一篇:Ubuntu查看并更改cuda版本指向
下一篇:错误1:Apache可移植运行库