1、nginx中配置pem 文件来实现https请求
server {
listen 443 ssl;
server_name localhost;
ssl_certificate /usr/local/nginx/cert/4332119_www.xx.pem;
ssl_certificate_key /usr/local/nginx/cert/4332119_www.xxx.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
root /usr/share/nginx/html;
location / {
try_files $uri $uri/ @router; #检测文件存在性重定向到首页目录 防止404
index index.html;
}
location @router {
rewrite ^.*$ /index.html last;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
2、nginx 中端口代理转发配置实现反向代理,业务场景:
阿里云oss 图片访问,不支持自定义域名 https访问,可以通过nginx来进行二次转发实现https访问
server {
listen 8088 ssl;
server_name localhost;
ssl_certificate /usr/local/nginx/cert/4332119_www.xx.pem;
ssl_certificate_key /usr/local/nginx/cert/4332119_www.xx.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
location / {
proxy_pass http://oss.xx.cn;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host oss.ihaier.cn;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
}
location @router {
rewrite ^.*$ /index.html last;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
3、nginx的常用命令
./nginx //启动nginx
./nginx -s stop //停止nginx
nginx的配置文件目录:conf
nginx的启动名称目录:sbin