Linux 安装与配置 Nginx 安装依赖包 1 yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
下载并解压安装包 1 2 3 4 5 cd /usr/local mkdir nginx cd nginx wget http://nginx.org/download/nginx-1.19.7.tar.gz tar -zxvf nginx-1.19.7.tar.gz
安装 Nginx 1 2 3 [root@aliyun nginx] [root@aliyun nginx-1.19.7] [root@aliyun nginx-1.19.7]
启动等命令 1 2 3 4 $ cd /usr/local/nginx/sbin $ ./nginx $ ./nginx -s stop $ ./nginx -s reload
Nginx 命令参数 Nginx 的参数包括:可以这样使用 /usr/local/nginx/sbin/nginx
-参数
-c
使用指定的配置文件而不是 conf 目录下的 nginx.conf
-t
测试配置文件是否正确,在运行时需要重新加载配置的时候,此命令非常重要,用来检测所修改的配置文件是否有语法错误
-v
显示 nginx 版本号
-V
显示 nginx 的版本号以及编译环境信息以及编译时的参数
例如,校验 nginx 文件的命令,如下:
1 /usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
返回下述代表正确,否则会显示多少行出错,更改即可:
1 2 3 [root@izbp10n2a7lzpams04dafvz nginx] nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
配置 SSL 1 2 3 4 5 6 listen 80; server_name api.zabbix.store; rewrite ^(.*)$ https://$host$1 ; location / { index index.html index.htm; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 server { listen 443 ssl; server_name api.zabbix.store; root html; index index.html index.htm; ssl_certificate ../api.zabbix.store.pem; ssl_certificate_key ../api.zabbix.store.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; location / { root html; index index.html index.htm; } }
异常记录 1. the “ssl” parameter requires ngx_http_ssl_module 异常详细信息:
1 nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf
解决:
1 2 3 4 5 $ cd /usr/local/nginx/nginx-1.19.7/ $ ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module $ cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak $ make $ cp ./objs/nginx /usr/local/nginx/sbin/
然后把 nginx.bak
恢复后重启就好
2.c compiler cc is not found 缺少 gcc-c++
的包
http 重定向到 https 1 2 3 4 5 6 7 8 9 10 11 12 server { listen 80; server_name domain.com; return 301 https://$server_name$request_uri ; } server { listen 443 ssl; server_name domain.com; [....] }