# 配置阿里云的epel-release源
$ rpm -ivh https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
# 直接yum安装nginx
$ yum install nginx
# 安装就这么简单方便,安装完成后,就可以使用systemctl来控制nginx的启动了
# 加入开机启动
$ systemctl enable nginx
# 启动nginx
$ systemctl start nginx
# 查看状态
$ systemctl status nginx
权限问题 Permission denied解决方案:
https://blog.csdn.net/guizishou00/article/details/81894168
# setsebool -P httpd_can_network_connect 1
配置nginx 配置
$ vim /etc/nginx/nginx.conf
# 配置检查ok后,不中断服务进行重载配置
$ systemctl reload nginx
查看日志:
$ vim/var/log/nginx/error.log
# 修改完配置后,检查配置
$ nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
# 要想访问nginx,还需要开放nginx监听的端口,这里为80端口,就开放80端口
$ firewall-cmd --add-port=80/tcp --permanent
$ firewall-cmd --reload
$ firewall-cmd --reload
ginx配置文件有错误
运行下面命令查看修改
nginx -t
已经启动nginx或者配置文件中的端口号被占用
检查端口是否被占用
netstat -tnlp
如果端口已经被占用,自己权衡一下是换个端口还是把占用端口的进程杀掉
检查nginx是否已经启动
ps -aux | grep nginx
如果已经启动使用下面命令干掉即可
pkill -9 nginx
重启nginx
service nginx restart
部署一个静态网页配置:
server { listen 80 default_server; listen [::]:80 default_server; server_name _; root /usr/share/nginx/html; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } }
文章评论