上一篇我们介绍了WordPress环境的基本配置与安装,如果你也跟我一样,有反向代理Tomcat的需求,那么可以参照我下面的配置
单纯的反向代理就直接在之前的
location ~ \.php$ {
root C:/WordPress; #这里改为你的WordPress地址
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
后面加上
location ^~ /tomcat/ { #这里表示将所有对http://xxx.com/tomcat/的请求通过下面规则进行转发
proxy_pass http://127.0.0.1:8080/; #这里根据tomcat端口号修改
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr; #这条和下一条很重要,之前在这里踩了坑
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
proxy_set_header设置原理见https://segmentfault.com/q/1010000008664742
WordPress伪静态的设置
在仪表盘的设置-固定链接中,选择自定义结构 后面填入内容可以百度,有很多种,我用的是 /%post_id%.html
然后在Nginx.conf中,将
location / {
root html;
index index.html index.htm;
}
中加入
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
即可
关于全站Https和Http跳转Https的配置
如果要做Https的话,首先要有SSL证书,腾讯云目前有免费一年的申请
首先找到负责80端口的server,就是server中有个 listen 80的,将其修改为
server {
listen 80;
server_name 你的主机地址;
return 301 https://$server_name$request_uri;
}
如果你有子域名,且跟我一样没有泛域名SSL证书的,则需要重复配置上面的server,将主机地址改为子域名,其他不变
接下来是SSL的配置,在Nginx.conf的http{XXXX}中新增如下server
server {
listen 443 ssl;
server_name 你的主机地址;
ssl_certificate cert.crt; #你的SSL证书名,将证书与nginx.conf放在同一目录
ssl_certificate_key cert.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / { #将你之前在监听80端口的server里配置的location移动到这里
root C:/wordpress;
index index.php index.html index.htm;
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
location ~ \.php$ {
root C:/wordpress;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME C:/wordpress/$fastcgi_script_name;
include fastcgi_params;
}
location ^~ /tomcat/ {
proxy_pass http://127.0.0.1:8080/;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
到这里SSL就配置完毕了,试试是否成功
文章评论