查看当前版本:
nginx -v
查看configure配置,大写的V,在不知道nginx配置的情况下非常有用。
nginx -V
输出如下:
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie'
查看配置是否成功
nginx -t
加载新的配置,又不影响当前访问:
nginx -s reload
升级新版本:
不显示nginx版本号,conf文件里添加.
server { listen 80; # 不显示nginx版本号 server_tokens off; # ... }
Nginx location配置测试
Nginx变量列表 Alphabetical index of variables
解决Nginx配置if语句多个条件的问题。
如下面的条件if语句多个条件:
if ($request_method = "POST" && $http_cookie !~* "auth")
解决办法:
set $val 'A'; if ($request_method = "POST") { set $val "${val}B"; } if ($http_cookie !~* "auth") { set $val "${val}C"; } if ($val = "ABC") { proxy_pass https://www.pythonxyz.com; break; }
重定向
# return code [text]; 返回 ok 给客户端 location = /ok { return 200 "ok"; } # return code URL; 临时重定向到 pythonxyz.com location = /redirect { return 302 https://www.pythonxyz.com; } # return URL; 和上面一样 默认也是临时重定向 location = /redirect { return https://www.pythonxyz.com; }
所有非正常请求都重定向到首页 default.conf
listen 80 default_server; listen [::]:80 default_server ipv6only=on; rewrite ^(.*) https://www.pythonxyz.com permanent; }
所有http请求跳转到https请求转换
server { listen 80; server_name pythonxyz.com; return 301 https://$host$request_uri; # ... }
文件重写
location = /favicon.ico { rewrite (.*) /static/favicon.ico last; } location = /robots.txt { rewrite (.*) /static/robots.txt last; }
# 防压测攻击(ab等) if ($http_user_agent ~ ApacheBench|webBench|Java/) { return 403; }
# 匹配 Android 和 iPhone 设备 if ( $http_user_agent ~* (Android|iPhone) ) { # 访问首页时跳转到移动版 rewrite ^/$ https://m.pythonxyz.com/ redirect; }
自动增加参数,如URL地址如下
www.pythonxxyz.com/ # Rewrite: www.pythonxyz.com/?foo=1 # url 2 www.pythonxxyz.com/?abc=2 # Rewrite: www.pythonxyz.com/?abc=2&foo=1 #解决办法 location /whatever { try_files $uri /index.php?foo=1&$args; }
条件可以是下列任意一种:
stat -c "%a %n" file , 755, 644
ModuleNotFoundError: No module named 'MySQLdb', ...
Ubuntu18.04下使用pyenv安装python报错:BUILD FAILED (Ubun ...
dell提供了工具远程查看服务器硬件状态,可以修改硬件的参数,可以远程连接过去直接修改,就不需要 ...
启动报undefined symbol: EVP_CIPHER_CTX_cleanup错误。op ...
ubuntu开启crontab日志记录及解决No MTA installed, discardi ...
暂时还没有评论,第一个来评论吧!