找到配置文件所在地址,进行编辑
/usr/local/nginx/conf$ sudo vim nginx.conf
在http部分中添加配置信息如下:
server {
listen 8888;
server_name localhost;
location ~/group[0-9]/ {
ngx_fastdfs_module;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location /static{
alias /home/ling/pytest/dailyfresh/static/;
}
location / {
# root html;
root /home/ling/pytest/dailyfresh/static/;
index index.html index.htm; # 默认页面
}
启动nginx
启动nginx:sudo /usr/local/nginx/sbin/nginx
重新启动:sudo /usr/local/nginx/sbin/nginx -s reload
查看进程:ps -ef|grep nginx
杀死进程: kill -9 进程id
验证nginx配置文件是否正确
进入nginx安装目录sbin下,输入命令:
sudo ./nginx -t # 此处不用root账户会报错
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 #打开 nginx
nginx -s reload|reopen|stop|quit #重新加载配置|重启|停止|退出 nginx
nginx -t #测试配置是否有语法错误
nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives]
-?,-h : 打开帮助信息
-v : 显示版本信息并退出
-V : 显示版本和配置选项信息,然后退出
-t : 检测配置文件是否有语法错误,然后退出
-q : 在检测配置文件期间屏蔽非错误信息
-s signal : 给一个 nginx 主进程发送信号:stop(停止), quit(退出), reopen(重启), reload(重新加载配置文件)
-p prefix : 设置前缀路径(默认是:/usr/local/nginx/)
-c filename : 设置配置文件(默认是:/usr/local/nginx/conf/nginx.conf)
-g directives : 设置配置文件外的全局指令