至此nginx安装成功。
https化 1.进入nginx安装目录,在该目录下新建cert目录,将nginx证书放入/usr/local/nginx目录下 cert目录下的证书 进入nginx安装目录conf,修改nginx.conf文件 cd /usr/local/nginx/conf vim nginx.conf修改后的nginx.conf
worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; client_max_body_size 1000M; location / { proxy_pass http://127.0.0.1:8080; root html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } # HTTPS server server { listen 443 ssl; server_name localhost; client_max_body_size 1000M; ssl_certificate ../cert/xxxxx.com.pem; #你的证书 ssl_certificate_key ../cert/xxxx.com.key; #你的key ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; location / { add_header Content-Security-Policy upgrade-insecure-requests; proxy_pass http://127.0.0.1:8080; #映射到本地的Tomcat8080端口 proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Proto https; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_redirect http:// https://; } } }至此,在浏览器地址栏输入 http://域名/项目名,或 https://域名/项目名。均可访问到部署在tomcat(端口为8080)下的项目。
nginx命令 #启动 cd /usr/local/nginx/sbin/ ./nginx #停止 ps -ef|grep nginx kill -9 主进程号 #重启 cd /usr/local/nginx/sbin/ ./nginx -s reload ./nginx -h #帮助 ./nginx -v #显示版本 ./nginx -V #显示版本和配置信息 ./nginx -t #测试配置 ./nginx -q #测试配置时,只输出错误信息 ./nginx -s stop #停止服务器