nginx安装教程

119 阅读1分钟

NGINX安装教程

本文档讲述liunx环境 nginx安装

一、安装一依赖包
  //一键安装上面四个依赖
    yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
二、下载并解压安装包
    //创建一个文件夹
    cd /usr/local
    mkdir nginx
    cd nginx
    //下载tar包
    wget http://nginx.org/download/nginx-1.13.7.tar.gz
    tar -xvf nginx-1.13.7.tar.gz

三、安装nginx
		//进入nginx目录
    cd /usr/local/nginx
    //进入目录
    cd nginx-1.13.7
    //执行命令 考虑到后续安装ssl证书 添加两个模块
    ./configure --with-http_stub_status_module --with-http_ssl_module
    //执行make命令
    make
    //执行make install命令
    make install

四、启动nginx
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
  1. nginx配置 添加server

      server {
      # 本教程端口为80
            listen       80;
            server_name  localhost;
            location /cdn/ {
                root   /usr/local/nginx/sbin/nginx/html;
                index  index.html index.htm;
                    autoindex on;
                    autoindex_exact_size off;
                    charset utf-8;
                    add_header 'Access-Control-Allow-Origin' '*';
                    add_header Access-Control-Allow-Credentials true;
                    add_header 'Access-Control-Allow-Methods' '*';
                    add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-  Since,Keep-Alive,Origin,User-Agent,X-Requested-With' always;
    
            }
    		
        }
    
ps -ef | grep nginx