nginx安装和配置

nginx安装和配置

Nginx的安装

开始前请确认gcc g++开发类库是否装好

# 更新yum
yum update

# 安装gcc等各种依赖
yum install -y gcc pcre pcre-devel openssl openssl-devel gd gd-devel

# 进入src目录下载nginx
cd /usr/local/src

# 下载
wget http://nginx.org/download/nginx-1.9.12.tar.gz

# 解压
tar -xvf nginx-1.9.12.tar.gz

# 改个名字
mv nginx-1.9.12 nginx

# 进入nginx目录进行configure配置
./configure

# 编译安装
make && make install

# 进入sbin目录
cd /usr/local/nginx/sbin

# 运行nginx
./nginx

# 关闭nginx
./nginx -s stop

# 查看状态
ps -ef | grep nginx

安装成功访问界面
nginx安装和配置_第1张图片
开启HTTPS

# 进入源码包 安装ssl模块
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

# 编译 不需要make install 否则就覆盖了
make

# 备份原来的Nginx
cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx_bak

# 将刚才编译好的Nginx覆盖原有的Nginx,需要先暂停Nginx
cp ./objs/nginx /usr/local/nginx/sbin/

# 查看安装情况
/usr/local/nginx/sbin/nginx -V

在这里插入图片描述

server{
    listen 80;
    listen       443 ssl;
    server_name localhost;
    charset      urf-8;
    client_max_body_size 10M;
    ssl_certificate      .pem 文件结尾的绝对路径;
    ssl_certificate_key  .key 文件结尾的绝对路径;
    ssl_session_timeout 5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; 
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;      
    index index.php index.html index.htm default.php default.htm default.html;
    root  /usr/local/nginx/html/;
    location / {
            alias   /usr/local/nginx/html/;
                try_files $uri $uri/  /index.html;
    }
}

/usr/local/nginx/sbin/nginx -t检验配置是否正确

你可能感兴趣的:(nginx安装和配置)