Think before you speak, read before you think.

nginx常用配置及操作

by

in

此博文意味着已经安装好了nginx php mysql : http://jpuyy.com/?p=764

0.nginx配制文件 /usr/local/nginx/conf/nginx.conf
1.启动nginx # /usr/local/nginx/sbin/nginx
2.Nginx 配置文件测试:#/usr/local/nginx/sbin/nginx -t //Debug 配置文件的关键命令需要重点撑握
3.使用ngx_http_access_module限制ip访问
location / {
deny 192.168.1.1;
allow 192.168.1.0/24;
allow 10.1.1.0/16;
deny all;
}
4.Nginx 配置文件修改重新加载
方法一:
首先查看进程PID值
#ps aux |grep nginx
root 2643 0.0 0.0 4804 664 ? Ss 16:36 0:00 nginx: master process /usr/local/nginx/sbin/nginx
平滑重启,输入 kill -HUP 2643

方法二:
可以reload配置文件,也等于动态加载了。
#/usr/local/nginx/sbin/nginx -s reload

5.把nginx弄为开机启动

Go to /etc/init.d and run sudo vim ngnix-passenger.sh
在里面写入

#!/bin/bash
# this script starts the nginx process attached to passenger
sudo /usr/local/nginx/sbin/nginx
sudo chmod +x /etc/init.d/ngnix-passenger.sh.
sudo /etc/init.d/ngnix-passenger.sh this will run all the code in the script.
Verify that it launches nginx before continuing.

Then run sudo update-rc.d ngnix-passenger.sh defaults while still in the /etc/init.d directory.
Once all of this is in place, reboot your server and ngnix should now be automatically spawned on startup


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *