centos7 安装 nginx

环境依赖

yum install -y gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel

下载压缩包

wget https://nginx.org/download/nginx-1.14.0.tar.gz

解压

tar zxvf nginx-1.14.0.tar.gz

configure

./configuare

编译和编译安装

make && make install

服务启动

./nginx

查看是否启动

  • 查进程 ps aux | grep nginx
  • 输入地址看效果

平滑启动

./nginx -s reload

nginx的配置文件 /usr/local/nginx/config/nginx.conf

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}
http {
    include       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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    gzip  on;  # 后端给前端提供数据的时候,是否将数据进行压缩。

    server {
        listen       80;
        server_name  localhost;
        location / {
            root   /home;
            index  index.html index.htm;
        }
    }
    
    include  vhost/*.conf; # 以后将server可以写在这个目录里
    
 }
# api.conf
server {
        listen       80;
        server_name  localhost;
        location / {
            root   /home;
            index  index.html index.htm;
        }
    }

 

posted @ 2020-03-23 22:48  尚尚123  阅读(164)  评论(0编辑  收藏  举报