repo追加
Nginx官网有yum的repo公开,可以从这里下载安装。
首先进入服务器,切换到root权限下。在[/etc/yum.repos.d/]下创建文件nginx.repo。文件内容计入如下:
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
追加后可以通过ls命令查看
# ls -l /etc/yum.repos.d/
total 32
。。。
-rw-r--r--. 1 root root 100 Dec 24 01:53 nginx.repo
安装Nginx
确认nginx包
# yum info nginx
Available Packages
Name : nginx
Arch : x86_64
Epoch : 1
Version : 1.12.2
Release : 1.el7_4.ngx
Size : 716 k
Repo : nginx/x86_64
Summary : High performance web server
URL : http://nginx.org/
License : 2-clause BSD-like license
Description : nginx [engine x] is an HTTP and reverse proxy server, as well as
: a mail proxy server.
执行安装
# yum install nginx
设定
系统启动时自动启动进程设定。
# systemctl enable nginx Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
启动和停止
# systemctl start nginx
浏览器输入本地IP:80可以看到如下效果
如果打不开的话,可能时80端口没有打开。通过以下命令打开。
# firewall-cmd --add-service=http --zone=public --permanent
# firewall-cmd --reload
然后重启服务
# systemctl restart nginx
停止服务命令。
# systemctl stop nginx
各种路径
路径 | 说明 |
---|---|
/etc/nginx/ | Nginx 设定文件保存路径 |
/etc/nginx/nginx.conf | 主设定文件路径 |
/var/log/nignx/ | log保存路径 |
/usr/share/nginx/html/ | web页面上公开html文件路径 |
/etc/nginx/nginx.conf 详解
默认内容
# cat /etc/nginx/nginx.conf
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}