3nginxweb相关配置

配置段
http{

}
http{},由ngx_http_core_module模块所引入

配置框架:
http{
upstream{
...
}

server{
    ...
    location URL{
        root "/path/to/somedir"
        ...
        if...{
            ...
        }
    } #类似httpd中的location可以多个
}#虚拟主机,可以多个
}

配置指令
server{}
定义一个虚拟主机
例如
server{
listen 8080;
server_name www.magedu.com;
root "/vhosts/web1";
}

mkdir -pv /vhosts/web1
vi /vhosts/web1/index.html
    hello
/usr/local/nginx/sbin/nginx -s reload
ss -tlnp
iptables -I INPUT -p tcp --dport 8080 -j ACCEPT
/etc/rc.d/init.d/iptables save
service iptables restart

listen
        指定监听的地址和端口
        listen address[:port];
        listen port;

server_name Name [...]
        后可跟多个主机,名称可以使用正则表达式(~开头)或通配符
        优先级:精确匹配>左侧通配符匹配检查>右侧通配符匹配>正则表达式匹配>default_server>第一个server
        server{
            server_name www.magedu.com;
        }
     server{
            server_name *.magedu.com;
      }

root path
    设置文档根目录

location [ = | ~ | ~* | ^~ ] uri {...}
    location @name {...}
    可以放在server中,location可以嵌套
    功能:允许根据用户请求的URI来匹配定义的各location,匹配到时,此请求将被相应的location匹配块中的配置所处理,例如做访问控制等功能;
    =:精确匹配
    ~:正则表达式模式匹配检查,区分字符大小写
    ~*:正则表达式模块匹配检查,不区分字符大小写
    ^~:URI的前半部分匹配,不支持正则表达式
    匹配优先级:=、^~、~、~*、不带任何符号的location
    server{
        listen 80;
        server_name www.magedu.com;
      location = / {
            root "/vhosts/web1";
      }

        location / {
            root "/vhosts/web1";
        }
     location /images/ {
            root "/vhosts/images";
     }
     location ~*  \.php$ {
            fcgipass
     }
    }
    
    http://www.magedu.com/bbs/index.php

alias path
用于location配置端,定义路径别名
注意:root表示指明路径为对应的location "/" URL;

index file
    默认主页面 inex inex.php index.html

error_page

ssl配置

nginx状态查看配置
url重写

if语句
防盗链

及定制访问日志格式
网络连接相关配置

猜你喜欢

转载自www.cnblogs.com/linux777/p/9373066.html