Say little, do much
nginx使用及配置
2019/09/26

命令行命令

start nginx             // 启动nginx

nginx.exe -s quit         //停止nginx  完整有序的停止nginx,并保存相关信息

nginx.exe -s stop            //停止nginx  是快速停止nginx,可能并不保存相关信息

nginx.exe -s reload         //重载nginx

nginx -v                            //查看nginx版本

apt-get install nginx        //ubuntu 安装nginx命令


打开文件列表

autoindex on;

autoindex_localtime on;

index index1.html index1.htm;

autoindex_exact_size off;        #关闭详细文件大小统计,让文件大小显示MB,GB单位,默认为b;

deny    all;


nginx 指定文件路径方式

location ^~ /static/ {

    root /www/root/;

}


如果一个请求的URI是/static/a.html时,web服务器将会返回服务器上的/www/root/static/a.html的文件。

location ^~ /static/ {

    alias /www/root/static/;

}

如果一个请求的URI是/static/a.html时,web服务器将会返回服务器上的/www/root/static/a.html的文件。注意这里是new_t,因为alias会把location后面配置的路径丢弃掉,把当前匹配到的目录指向到指定的目录。

注意:

1. 使用alias时,目录名后面一定要加"/"。

2. alias会把location的路径丢弃掉,把当前匹配到的目录指向到指定的目录。

3. alias在使用正则匹配时,必须捕捉要匹配的内容并在指定的内容处使用。

4. alias只能位于location块中。(root可以不放在location中)



nginx解决跨域请求资源或接口

location /apis { #添加访问目录为/apis的代理配置

    rewrite  ^/apis/(.*)$ /$1 break;

    proxy_pass  http://localhost:82;

}


发表评论

Powered By © 奇迹云   备案号:粤ICP备17082613号

本站部分资源来源于互联网网友交流,只供网络测试和学习交流所用、所有版权归原权利人,如有关资源侵犯了你的权益,请联系告之,我们将于第一时间删除!

用户名:

密码:

邮箱:

*
*
*