nginx反向代理基本配置【目录】1.安装nginxpkill-9apache2#关闭apachesudoaptinstallnginx#安装nginx,使用Ubuntu的包管理工具apt-get2。修改apache端口号,防止报错sudovim/etc/apache2/ports.conf#修改端口为81,防止和nginx重复导致重启失败sudoserviceapache2start#启动apache服务器,代理目标服务器3.在nginx目录下添加服务器配置cd/etc/nginx/conf.d/#进入配置文件目录vimhost.conf#创建自定义配置文件。新安装的nginx在conf.d目录下没有任何文件,新建一个host.conf文件。conf.d下的所有文件都导入到nginx目录下的nginx.conf中。com;indexindex.htmlindex.htmindex.phproot/var/www/html;位置/{proxy_passhttp://localhost:81;proxy_redirect关闭;proxy_set_header主机$host;proxy_set_headerX-Real-IP$remote_addr;proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;proxy_next_upstream错误超时invalid_headerhttp_500http_502http_503http_504;proxy_max_temp_file_size0;proxy_connect_timeout90;代理发送超时90;proxy_read_timeout90;proxy_buffer_size4k;代理缓冲区432k;proxy_busy_buffers_size64k;proxy_temp_file_write_size64k;}}服务器{听80;服务器名称info.triste.com;indexindex.htmlindex.htmindex.phproot/var/www/html;位置/{proxy_passhttp://localhost:81;proxy_redirect关闭;proxy_set_header主机$host;proxy_set_headerX-Real-IP$remote_addr;proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;proxy_next_upstream错误超时invalid_headerhttp_500http_502http_503http_504;proxy_max_temp_file_size0;proxy_connect_timeout90;代理发送超时90;proxy_read_timeout90;proxy_buffer_size4k;代理缓冲区432k;proxy_busy_buffers_size64k;proxy_temp_file_write_size64k;}}重启nginxsudoservicenginxreload效果图nginx访问反向代理到apache反向代理到apache如何配置SSL到nginx和反向代理?假设你有ss如果是证书:直接上传代码如下:server{listen443;服务器名称www.domain.com;#填写绑定证书sslon的域名;ssl_certificate1_www.domain.com_bundle.crt;ssl_certificate_key2_www.domain.com.key;ssl_session_timeout5m;ssl_protocolsTLSv1TLSv1.1TLSv1.2;#根据此协议配置ssl_ciphersECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;#根据此套件配置ssl_prefer_server_cipherson;位置/{根html;#站点目录索引index.htmlindex.htm;}}上面的代码配置了www.domain.com,现在可以通过https://www.domain.com访问了。配置反向代理:server{listen443;服务器名称blog.domain.com;#填写绑定证书sslon的域名;ssl_certificateblog.domain.com_bundle.crt;ssl_certificate_keyblog.domain.com.key;ssl_session_timeout5m;ssl_protocolsTLSv1TLSv1.1TLSv1.2;#根据这个协议配置ssl_ciphersECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;#根据这个包配置ssl_prefer_server_ciphers开启;位置/{proxy_passhttp://localhost:81;proxy_redirect关闭;proxy_set_header主机$host;proxy_set_headerX-Real-IP$remote_addr;proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;proxy_max_temp_file_size0;proxy_connect_timeout90;代理发送超时90;proxy_read_timeout90;proxy_buffer_size4k;代理缓冲区432k;proxy_busy_buffers_size64k;有时需要重新颁发证书。全站加密编辑nginx.conf文件。Ubuntu上的位置是:/etc/nginx/nginx.confhttp{#沉略部分server{rewrite^(.*)https://$host$1permanent;}}上面的代码可以自动从http跳转到https,从而实现全站加密。
