一、yum安装
yum -y install nginx
二、查看配置
which nginx #安装路径
nginx -h #配置文件路径
三、设置快捷,开机启动
service nginx start 启动,yum安装默认是开机启动,配置好的。
但因版本会其他原因出现以下错误需要手动配置执行以下命令。
[root@lck nginx]# service nginx start
Redirecting to /bin/systemctl start nginx.service
cd /etc/init.d #查看是否有nginx文件,这个就是默认启动文件。
vim nginx
加入以下配置:
#!/bin/bash
#
# chkconfig: - 85 15
# description: Nginx is a World Wide Web server.
# processname: nginx
nginx=/usr/sbin/nginx #安装路径
conf=/etc/nginx/nginx.conf #配置文件路径
case $1 in
start)
echo -n "Starting Nginx"
$nginx -c $conf
echo " done"
;;
stop)
echo -n "Stopping Nginx"
killall -9 nginx
echo " done"
;;
test)
$nginx -t -c $conf
;;
reload)
echo -n "Reloading Nginx"
ps auxww | grep nginx | grep master | awk '{print $2}' | xargs kill -HUP
echo " done"
;;
restart)
$0 stop
$0 start
;;
show)
ps -aux|grep nginx
;;
*)
echo -n "Usage: $0 {start|restart|reload|stop|test|show}"
;;
esac
三、配置生效
设置执行权限:chmod +x /etc/init.d/nginx
设置开机启动:chkconfig nginx on
四、使用命令
service nginx start
service nginx stop
service nginx restart
service nginx reload
五、 搭建文件服务器
1.修改nginx.conf里,第一行
user ngix; # 不同版本的不一样
改为
user root;
2.加载server,文件位置
autoindex on; # 显示文件目录
autoindex_exact_size on;# 显示文件大小
autoindex_localtime on;# 显示文件时间
server {
listen 8100 default_server;
listen [::]:8100 default_server;
server_name _;
#root /usr/share/nginx/html;
root /;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
3.刷新重启即可