centos7安装nginx

#gcc安装,nginx源码编译需要
yum install gcc-c++

#PCRE pcre-devel 安装,nginx 的 http 模块使用 pcre 来解析正则表达式
yum install -y pcre pcre-devel

rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum -y install nginx

启动 验证

[root@localhost local]# systemctl start nginx
[root@localhost local]# ps -ef |grep nginx
root      4744     1  0 10:31 ?        00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx     4745  4744  0 10:31 ?        00:00:00 nginx: worker process
root      4837 13235  0 10:31 pts/0    00:00:00 grep --color=auto nginx
[root@localhost local]#

centos7安装nginx_第1张图片
nginx配置目录
/etc/nginx/nginx.conf

vi /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;     # 这里/etc/nginx/conf.d/*.conf是引入默认的server配置,这里我们可以去掉,配置成自己的项目
}

查看默认配置

cd /etc/nginx/conf.d

centos7安装nginx_第2张图片

vi default.cong

这就是默认的配置,照此模板,我们可以配置自己的服务
centos7安装nginx_第3张图片

测试配置文件是否在正确:nginx -t
启动:service nginx start 会有如下输出
Redirecting to /bin/systemctl start nginx.service
启动:systemctl start nginx 无输出
重启:nginx -s reload
查看nginx进程:ps -ef |grep nginx
关闭服务:nginx -s stop或者kill -9 pid

卸载

停止Nginx:service nginx stop
删除Nginx的自动启动:chkconfig nginx off
删除Nginx本地文件:
rm -rf /usr/sbin/nginx
rm -rf /etc/nginx
rm -rf /etc/init.d/nginx
yum清理:yum remove ngin

你可能感兴趣的:(nginx,nginx)