linux简单配置nginx并实现https转发
在官网下载了nginx安装包(linux版)后,解压到服务器目录。
要实现https(443端口,其他端口可以不用此操作),需要下载nginx支持的ssl依赖:
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel 或者 yum install openssl openssl-devel
只配置简单的几项:
1、监听80端口 普通转发
2、https转发
3、负载均衡配置
4、静态资源访问
修改安装目录下的配置文件conf/nginx.conf
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; #监听80端口 普通转发 server{ listen 80; server_name www.xxxx.com xxxx.com; charset utf-8; rewrite_log on; #系统api location / { proxy_pass https://www.yyyy.com/; } } #https转发 server { listen 443 ssl; server_name www.aaaa.com; ssl on; ssl_certificate 上面域名的证书公钥地址; #证书公钥 ssl_certificate_key 上面域名的证书私钥地址; #证书私钥 ssl_session_timeout 5m; location / { proxy_pass http://localhost:8080; } } #负载均衡配置 upstream kxrwprobject { server localhost:8088; server localhost:8089; } server { listen 443 ssl; server_name www.bbb.com; ssl_certificate 上面域名的证书公钥地址; #证书公钥 ssl_certificate_key 上面域名的证书私钥地址; #证书私钥 ssl_session_timeout 5m; #系统api location / { proxy_pass http://kxrwprobject/; } } #静态资源访问 server{ listen 80; server_name www.ccc.com; charset utf-8; rewrite_log on; #系统api location / { root /usr/local/nginx/html; } } }
。
不管什么时候都别忘了最初的梦想