Nginx_入门
nginx及其模块的工作方式在配置文件中确定。默认情况下,配置文件名为
nginx.conf,并放置在目录/usr/local/nginx/conf、/etc/nginx或/usr/local/etc/nginx中in this case a signal is sent directly to a process with a given process ID. The process ID of the nginx master process is written, by default, to the
nginx.pidin the directory/usr/local/nginx/logsor/var/run. For example, if the master process ID is 1628, to send the QUIT signal resulting in nginx’s graceful shutdown, execute:
1 | kill -s QUIT 1628 |
- For getting the list of all running nginx processes, the
psutility may be used, for example, in the following way:
1 | ps -ax | grep nginx |
[!NOTE]For more information on sending signals to nginx, see Controlling nginx.
1 | #重启前不要忘记用 sudo nginx -t 检查配置是否无错 |
[ !NOTE]不推荐使用
sudo systemctl restart nginx 因为这个样子会中断正在运行的服务,上面则反之
配置文件的结构
nginx由由配置文件中指定的指令控制的模块组成。指令分为简单指令和块指令。一个简单的指令由名称和参数组成,用空格分隔,并以分号(;)结尾。块指令的结构与简单指令相同,但它不是分号,而是以一组被大括号({和})包围的附加指令结束。如果块指令可以在大括号内包含其他指令,则称为上下文(示例:事件、http、服务器和位置)。
放置在任何上下文之外的配置文件中的指令都被视为在主上下文中。events和http指令位于main下文、http中的server和server中location中。
#符号后的其余行被视为注释。
主要框架
- worker_processes
- event
- http{mime.types}
- server{ listen;host_name;location}
location块里的方法名
1 | root URL #指定根目录 |
location 正则表达式
1 | #还没有公布,未学习到 |
案例
1 | #gzip on; |
[!WARN]rewrite 的网页最好写绝对路径,重写浏览器只解析相对路径,只看浏览器的URL,也就是定义要重写的路径
beginner