Nginx常用配置

197 阅读1分钟

nginx 常用命令

centos 通过 yum 命令安装的 nginx

  • nginx -t 验证
  • service nginx start 启动
  • service nginx restart 重启

location & rewrite

(location =) > (location 完整路径) > (location ^~ 路径) > (location ~,~* 正则顺序) > (location 部分起始路径) > (/)

proxy_pass - 参考

在nginx中配置proxy_pass代理转发时

  • 如果在proxy_pass后面的url加/,表示绝对根路径;
  • 如果没有/,表示相对路径,把匹配的路径部分也给代理走。

假设下面四种情况分别用 http://192.168.1.1/proxy/test.html 进行访问。

  1. 第一种:
# 代理到URL:http://127.0.0.1/test.html
location /proxy/ {
    proxy_pass http://127.0.0.1/;
}

  1. 第二种(相对于第一种,最后少一个 / )
# 代理到URL:http://127.0.0.1/proxy/test.html
location /proxy/ {
    proxy_pass http://127.0.0.1;
}

  1. 第三种:
# 代理到URL:http://127.0.0.1/aaa/test.html
location /proxy/ {
    proxy_pass http://127.0.0.1/aaa/;
}
  1. 第四种(相对于第三种,最后少一个 / )
# 代理到URL:http://127.0.0.1/aaatest.html
location /proxy/ {
    proxy_pass http://127.0.0.1/aaa;
}