我最近将我们的主页迁移到ASP.NET Core 1.0。 这使我在Linux环境中移动网站。 我们也有这个网站这是一个WordPress的博客/博客。 除了W3 Total Cache之外,所有迁移都正常。 这是我做的。
安装的PHP-FPM和DNX都在Nginx的反向代理之后。 这是文件夹层次结构。 / var / www / aspnet / var / www / wordpress
这里是所有与Nginx相关的configuration文件
/etc/nginx/nginx.conf
user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/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"'; log_format scripts '$document_root$fastcgi_script_name > $request'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; }
/etc/nginx/sites-available/xyz.com
server { listen 443 ssl http2; server_name xyz.com www.xyz.com; ssl_certificate /etc/ssl/certs/cert_chain.crt; ssl_certificate_key /etc/ssl/private/xyz.private.txt; access_log /var/log/nginx/scripts.log scripts; # Global restrictions configuration file. # Designed to be included in any server {} block. location = /favicon.ico { log_not_found off; access_log off; } location = /robots.txt { allow all; log_not_found off; access_log off; } # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac). # Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban) location ~ /\. { deny all; } # Deny access to any files with a .php extension in the uploads directory # Works in sub-directory installs and also in multisite network # Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban) location ~* /blog/(?:uploads|files)/.*\.php$ { deny all; } gzip_types text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon; location ~ ^/blog/\.(css|htc|less|js|js2|js3|js4)$ { expires 31536000s; add_header Pragma "public"; add_header Cache-Control "max-age=31536000, public"; } location ~ \.(html|htm|rtf|rtx|svg|svgz|txt|xsd|xsl|xml)$ { expires 3600s; add_header Pragma "public"; add_header Cache-Control "max-age=3600, public"; } location ~ \.(asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|eot|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|json|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|otf|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|ttf|ttc|wav|wma|wri|woff|xla|xls|xlsx|xlt|xlw|zip)$ { expires 31536000s; add_header Pragma "public"; add_header Cache-Control "max-age=31536000, public"; } location / { proxy_pass http://unix:/var/www/aspnet/kestrel.sock; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection keep-alive; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_cache_bypass $http_upgrade; } location /phpmyadmin/ { alias /var/www/phpMyAdmin/; index index.php; } location ~ ^/phpmyadmin/(.+\.php)$ { alias /var/www/phpMyAdmin/$1; fastcgi_pass unix:/run/php/phpmyadmin.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $request_filename; # From fastcgi_params fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param REQUEST_URI $request_uri; fastcgi_param DOCUMENT_URI $document_uri; fastcgi_param DOCUMENT_ROOT /var/www/phpMyAdmin; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_PORT $remote_port; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name; fastcgi_param REDIRECT_STATUS 200; } location /blog/ { try_files $uri $uri/ index.php?q=$request_uri; alias /var/www/wordpress/; index index.php; } location ~ \.php$ { include /var/www/wordpress/nginx.conf; try_files $uri $uri/ index.php?q=$request_uri =404; alias /var/www/wordpress/$1; fastcgi_pass unix:/run/php/phpmyadmin.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_split_path_info ^(.+\.php)(/.+)$; # From fastcgi_params fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param REQUEST_URI $request_uri; fastcgi_param DOCUMENT_URI $document_uri; fastcgi_param DOCUMENT_ROOT /var/www/wordpress; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_PORT $remote_port; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name; fastcgi_param REDIRECT_STATUS 200; } }
/var/www/wordpress/nginx.conf – 这是W3 Total Cache插件生成的文件。
# BEGIN W3TC Page Cache core set $w3tc_rewrite 1; if ($request_method = POST) { set $w3tc_rewrite 0; } if ($query_string != "") { set $w3tc_rewrite 0; } if ($request_uri !~ \/$) { set $w3tc_rewrite 0; } if ($http_cookie ~* "(comment_author|wp\-postpass|w3tc_logged_out|wordpress_logged_in|wptouch_switch_toggle)") { set $w3tc_rewrite 0; } if ($http_cookie ~* "(w3tc_preview)") { set $w3tc_rewrite _preview; } set $w3tc_ssl ""; if ($scheme = https) { set $w3tc_ssl _ssl; } set $w3tc_enc ""; if ($http_accept_encoding ~ gzip) { set $w3tc_enc _gzip; } set $w3tc_ext ""; if (-f "$document_root/var/www/wordpress/wp-content/cache/page_enhanced/$http_host/$request_uri/_index$w3tc_ssl$w3tc_rewrite.html$w3tc_enc") { set $w3tc_ext .html; } if (-f "$document_root/var/www/wordpress/wp-content/cache/page_enhanced/$http_host/$request_uri/_index$w3tc_ssl$w3tc_rewrite.xml$w3tc_enc") { set $w3tc_ext .xml; } if ($w3tc_ext = "") { set $w3tc_rewrite 0; } if ($w3tc_rewrite = 1) { rewrite .* "/var/www/wordpress/wp-content/cache/page_enhanced/$http_host/$request_uri/_index$w3tc_ssl$w3tc_rewrite$w3tc_ext$w3tc_enc" last; } # END W3TC Page Cache core
一旦我完成了上面的configuration。 我能够运行WordPress的永久链接。 但是当我打开/博客/或/博客/ WP – pipe理员/它显示没有find。 为了解决问题,我在nginx中添加了一些自定义日志logging,如下所示
log_format scripts '$document_root$fastcgi_script_name > $request';
这是什么日志显示
/var/www/wordpress//blog/wp-admin/index.php> GET /blog/wp-admin/index.php HTTP / 2.0 /var/www/wordpress//blog/index.php> GET / blog / HTTP / 2.0
我尝试了很多解决scheme 他们都假设父母的网站是wordpress。 在我的情况下,父站点build立在DotNet Core 1上。/ blog是我的wordpress博客。 这个问题必须是错误的重写规则之一。
总结这个问题,我W3总caching不是问题。 我可以没有这个生活。 现在的问题是,当你把一个WordPress站点作为一个子站点托pipe到一个静态站点时,重写规则。 可以忽略W3总cachingconfiguration部分。 我已经托pipe网站,如mydomain.com/blog,重写规则没有得到应用。 截至目前,我尝试了很多方法。 如果有人已经实现Wordpress作为一个纯粹的子目录而不是多站点子目录。 他们可以提供他们成功的configuration。
这不会直接回答你的问题,但可能是一个更好的select,你可能没有考虑。 使用Nginx页面caching,而不是使用插件进行caching。 这要快得多,因为你不必打电话给PHP,这消除了很多开销。
不利的一面是,要使Nginxcaching无效,除非你支付商业版本的Nginx。 你可以用插件来构buildNginx,但是Wordpress / Nginxcaching集成并不好。 没有,我发现工作很好。 所以你需要仔细设置你的caching最大限度的生活。 有趣的是,在一个繁忙的网站caching几秒钟可以有好处。 我的网站变化很less,如果我需要,我可以rm -rf正确的目录,其中nginx页面caching居住 – 这实际上是在内存中。
我在这里有一个教程,会有很多其他的。 这里有一篇关于Nginx微型caching的大文章。
如果网站消失,SF喜欢页面上的实际数据。
在你的nginx.conf中
fastcgi_cache_key "$scheme$request_method$host$request_uri";
在你的网站文件的顶部,或在你的nginxconfiguration
fastcgi_cache_path /dev/shm/nginxcache levels=1:2 keys_zone=CACHENAME:10m inactive=1440m; # Centos / Amazon Linux in RAM, 1440 minutes = 24 hours
在您的位置块调用PHP
fastcgi_pass php56-fpm; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_cache_use_stale error timeout invalid_header http_500; fastcgi_ignore_headers Cache-Control Expires Set-Cookie; fastcgi_cache CACHENAME; fastcgi_cache_valid 200 1440m; fastcgi_cache_valid 403 404 405 410 414 301 302 307 60m; add_header X-Cache $upstream_cache_status; # This can be removed if desired fastcgi_cache_methods GET HEAD; fastcgi_keep_conn on;
我链接到的教程有更多的信息和解释。
你需要一些步骤来解决这个问题(从目前情况来看)…
请参阅: https : //codex.wordpress.org/Giving_WordPress_Its_Own_Directory
将WordPress核心文件从/var/www/wordpress到/var/www/wordpress/blog 。 (提示: mv /var/www/wordpress /var/www/blog && mkdir /var/www/wordpress && mv /var/www/blog /var/www/wordpress )
复制/var/www/wordpress/blog/index.php到目录/var/www/wordpress/ 。
编辑/var/www/wordpress/index.php文件并更改行require( dirname( __FILE__ ) . '/wp-blog-header.php' ); require( dirname( __FILE__ ) . '/blog/wp-blog-header.php' ); 。
现在,Nginx的一部分。 这里是相关部分的变化…
location /blog { root /var/www/wordpress; index index.php; try_files $uri $uri/ /blog/index.php?q=$request_uri; } location ~ \.php$ { root /var/www/wordpress; index index.php; try_files $uri $uri/ /blog/index.php?q=$request_uri =404; # other configuration directives }
有两个主要的变化:
alias指令成为root try_files指令包含index.php之前的/blog/ 。 我希望这有帮助!