nginx 配置 https过程及问题总结

1.准备

平台:腾讯云 nginx
SSL:TrustAsia TLS RSA CA (腾讯云提供免费)
SSL安装:参考证书安装指引

2.nginx.conf配置参考
# Settings for a TLS enabled server.
    server {
        listen       443 ssl;
        server_name  www.*****.com; #绑定证书的域名
#       ssl on;  #因为要同时使用http和https访问,这里关掉ssl在listen中添加ssl;
        ssl_certificate /***/1_*****.com_bundle.crt;  #证书文件
        ssl_certificate_key /***/2_*****.com.key;     #私钥文件
        ssl_session_timeout  5m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #官方提供的协议配置
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; #官方套件配置
        ssl_prefer_server_ciphers on;
        location / {
            root  /**/**/html; #站点目录
            index index.html index.htm index.php;
        }
        #以下location复制自http server
        location ~ \.php {
             fastcgi_pass   127.0.0.1:9000;
             fastcgi_index  index.php;
             fastcgi_split_path_info ^(.+\.php)(.*)$;
             fastcgi_param PATH_INFO $fastcgi_path_info;
             fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
             include        fastcgi_params;
        }

配置后#nginx -t 测试配置是否有误,无误即可重启nginx (service nginx restart);
同时使用http和https可以参考这里

3.防火墙配置

首先查看端口:

# netstat -anp

Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      3183/php-fpm: maste 
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      2366/mysqld         
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      7399/nginx: master  
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      750/sshd            
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      7399/nginx: master  

433端口开启,如果没有开启开启即可:

# vi /etc/sysconfig/iptables

-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A INPUT -p icmp -j ACCEPT

# iptables -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT
4.可能遇到的问题

nginx https配置后无法访问,可能防火墙在捣鬼
nginx 访问html正常 访问php 404
nginx配置https之后只有首页能访问,其他页面404

你可能感兴趣的:(问题总结,经验)