1.nginx在centos7环境安装
打开linux终端输入如下命令,安装nginx
yum update
yum -y install nginx
或者
rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum -y install nginx
2.nginx配置web server
配置文件nginx.conf通用配置如下
user root root;
worker_processes 4;
pid /run/nginx.pid;
daemon off;
events { }
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
gzip_disable "msie6";
include ./global.conf;
}
其中,和nginx.conf在同级目录下的global.conf文件配置如下(webserver配置)
server {
listen 0.0.0.0:80;
server_name _;
location / {
root /var/www/html/website;
index index.html index.htm;
}
access_log /var/log/nginx/default_access.log;
error_log /var/log/nginx/default_error.log;
}
3.启动nginx
在终端输入如下命令,启动nginx
nginx -c /home/sample/nginx/nginx.conf
启动成功后,访问web路径localhost:80,其中80为global.conf配置的端口
注意:nginx.conf 第一行,用户名改为登录的用户组、用户名