配置的是nginx转发,前提是你已经安装了nginx的软件并已经正常打开网页,安装好SSL协议,能打开https网页
下面是配置:
需要的话可以根据需求修改
server {
listen 80;
server_name c21r.z1r053.com;
return 301 https://$host$request_uri;
}
upstream websocket {
server c21r.z1r053.com:2666;
}
server {
listen 443;
server_name c21r.z1r053.com;
ssl on;
root /home/wwwroot/cren/public;
index index.html index.php;
location ~* ^.+.(jpg|jpeg|gif|png|bmp|js|css)$ {
access_log off;
root /home/wwwroot/cren/public;
expires 30d;
break;
}
location ~ .php$ {
root /home/wwwroot/cren/public; #指定php的根目录
fastcgi_pass 127.0.0.1:9000;#php-fpm的默认端口是9000
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/wwwroot/cren/public$fastcgi_script_name;
include fastcgi_params;
}
ssl_certificate cert3/214550577690872.pem;
ssl_certificate_key cert3/214550577690872.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
root /home/wwwroot/cren/public;
index index.html index.php;
try_files $uri $uri/ /index.php?$query_string;
proxy_pass http://c21r.z1r053.com:2666;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header X-Real-IP $remote_addr;
}
access_log /var/log/nginx/c21r.z1r053.com.log;
}
配置之后发现wss协议能打开了,但是https协议又出现问题,所以这里有几个坑需要注意下一:
1. proxy_pass http://c21r.z1r053.com:2666; 最开始这里忘记加端口号了,所以wss协议还是不通,加上端口号就好了
2.配置代理之后图片文件和css,js文件打不开,所以又配置了下面的内容解决了:
location ~* ^.+.(jpg|jpeg|gif|png|bmp|js|css)$ {
access_log off;
root /home/wwwroot/cren/public;
expires 30d;
break;
}
3.配置之后加入http转https:
server {
listen 80;
server_name c21r.z1r053.com;
return 301 https://$host$request_uri;
}
4.location加入重写后js文件才能正常打开:
try_files $uri $uri/ /index.php?$query_string;