Nginx可以作为静态页面的 web 服务器,同时还支持 CGI 协议的动态语言,比如 pe rl 、 php等。但是不支持 java 。 Java 程序只能通过与 tomcat 配合完成。 Nginx 专为性能优化而开发,性能是其最重要的考量 实现上非常注重效率 ,能经受高负载的考验 有报告表明能支持高达 50,000 个并发连接数。
【1】自我路由
背景:请求格式如/operation/user,但是nginx.conf配置文件总location均是如/user格式拦截。那么如何在最小修改情况下实现请求拦截呢?
解决方法一:使用正则修改location的拦截规则,如/opertaion/user|/user。
这样既拦截了请求也保留了原先的配置。但是这种方法需要修改每个location,比较麻烦。
推荐方案:添加自我路由。
拦截/operation/开头的并再次转发给自己:
location /operation/ {
proxy_pass_header Server;
proxy_headers_hash_max_size 5120;
proxy_headers_hash_bucket_size 640;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_pass http://127.0.0.1:21100/;
}
【2】命令行参数
nginx支持一系列命令行参数,提供快捷功能如停止、启动、测试配置文件等。
① nginx -s [选项]
nginx -s signal
— 给master process 发送指令,指令值可以如下:
stop — 快速停止
quit — 优雅退出
reload — 重新读取新的配置文件,启动新的worker processes,平滑退出老的worker proesses
reopen — 打开日志文件
② nginx -t 测试配置文件
[root@localhost ~]# cd /usr/local/nginx/sbin/
[root@localhost sbin]# ./nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
③ nginx -T 测试配置文件并输出
④ nginx -v 查看nginx版本
[root@localhost sbin]# ./nginx -v
nginx version: nginx/1.16.1
⑤ nginx -V 查看nginx版本、编译版本与配置参数
[root@localhost sbin]# ./nginx -V
nginx version: nginx/1.16.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --with-http_ssl_module
⑥ nginx -g directives 命令方式进行配置
实例如下:
nginx -g "pid /var/run/nginx.pid; worker_processes `sysctl -n hw.ncpu`;"