Skip to content

Nginx

nginx安装-centos

安装yum-utils

plain
yum install yum-utils

创建/etc/yum.repos.d/nginx.repo文件并配置

shell
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

安装Nginx

plain
sudo yum install nginx

查看Nginx安装的目录

plain
whereis nginx

目录说明

plain
/usr/sbin/nginx                                     //运行Nginx
/usr/lib64/nginx 
/etc/nginx                                              //存放配置文件
/usr/share/nginx                                    //Nginx默认页面
/usr/share/man/man8/nginx.8.gz

运行和停止

plain
cd /usr/sbin/
./nginx
./nginx -s stop

gzip配置

gzip  on;
gzip_min_length 1k;
gzip_comp_level 2;
gzip_types text/plain text/xml application/xml application/javascript text/css;
text
yum install pcre pcre-devel
yum install -y zlib-devel
yum install -y openssl-devel


./configure
    --sbin-path=/usr/local/nginx
    --conf-path=/usr/local/nginx.conf
    --pid-path=/usr/local/nginx.pid
    --with-http_ssl_module
    --with-pcre=../pcre2-10.39
    --with-zlib=../zlib-1.3
text
server {
     #SSL 默认访问端口号为 443
     listen 443 ssl;
     #请填写绑定证书的域名
     server_name domain;
     #请填写证书文件的相对路径或绝对路径
     ssl_certificate domain.crt;
     #请填写私钥文件的相对路径或绝对路径
     ssl_certificate_key domain.key;
     ssl_session_timeout 5m;
     #请按照以下协议配置
     ssl_protocols TLSv1.2 TLSv1.3;
     #请按照以下套件配置,配置加密套件,写法遵循 openssl 标准。
     ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
     ssl_prefer_server_ciphers on;
     location / {
        proxy_set_header   Host    $http_host;
        proxy_set_header   Remote_Addr    $remote_addr;
        proxy_set_header   X-Real-IP    $remote_addr;
        proxy_set_header   X-Forwarded-For    $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto        $scheme;
        proxy_pass http://127.0.0.1:6111;
     }
}
server {
     listen 80 ;
     #请填写绑定证书的域名
     server_name domain;
     #把http的域名请求转成https
 	 return 301 https://domain$request_uri; 
}

nginx编译安装