nginx基础命令:
sudo nginx // 开启nginx服务器
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
文件操作相关:
sudo vim XXX(文件名) // 打开文件
:q // 退出vim编辑模式
:wq! // 保存退出vim模式
sudo touch xxx(文件名) // 创建一个文件
rm -rf xxx // 删除xxx文件夹
rm -f python.py // 删除xx文件
权限相关:
linux chmod xxx
权限分为三种:读(r=4),写(w=2),执行(x=1)
eg:
可读可执行(rx=5=4+1)、可读可写(rw=6=4+2)、可读可写可执行(rwx=7=4+2+1)
chmod 755:
1.文件所有者可读可写可执行
2.与文件所有者同属一个用户组的其他用户可读可执行
3.其它用户组可读可执行
nginx配置相关:
nginx代理配置:
在nginx中配置proxy_pass时,如果是按照^~匹配路径时,要注意proxy_pass后的url最后的/,当加上了/,相当于是绝对根路径,则nginx不会把location中匹配的路径部分代理走;如果没有/,则会把匹配的路径部分也给代理走。
location ^~ /support/
{
proxy_cache js_cache;
proxy_set_header Host www.xudengwei.com;
proxy_pass http://www.xudengwei.com/;
}
如上面的配置,如果请求的url是http://servername/support/test.html
会被代理成http://www.xudengwei.com/test.html
而如果这么配置
location ^~ /support/
{
proxy_cache js_cache;
proxy_set_header Host www.xudengwei.com;
proxy_pass http://www.xudengwei.com;
}
则会被代理到http://www.xudengwei.com/support/test.htm
当然,我们可以用如下的rewrite来实现/的功能
location ^~ /support/
{
proxy_cache js_cache;
proxy_set_header Host www.xudengwei.com;
rewrite /support/(.+)//1 break;
proxy_pass http://www.xudengwei.com;
}