Last active
August 29, 2015 14:06
-
-
Save pvolyntsev/17b7a72d0e89ac31817d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# задача: приложение реализовать на Yii, а статьи публиковать в Wordpress и всё это на одном адресе и на одном порту : http://icons8.com/ | |
# обсуждается на хабре http://habrahabr.ru/company/dataart/blog/236635/ | |
# там же ссылки ещё на 5 примеров интеграции Wordpress и Yii | |
# конфиг верхнего уровня для перенаправления запросов на приложение Yii или блог wordpress | |
server { | |
listen 80; | |
#server_name icons8.com; | |
#error_log /var/log/icons8.com/error.log; | |
#access_log /var/log/icons8.com/access.log; | |
charset utf-8; | |
# тут ещё сжатие gzip и кэширование ответов веб-сервера можно настроить | |
location / { | |
proxy_intercept_errors on; # чтобы перехватить ошибки | |
error_page 404 = @wordpress_fallback; # при ошибке Page Not Found запросить wordpress | |
proxy_pass http://127.0.0.1:8889; # запросить приложение на Yii | |
} | |
location @wordpress_fallback { | |
proxy_intercept_errors off; # пусть теперь wordpress отрисовывает страницы ошибок | |
proxy_pass http://wordpress_upstream; # запросить wordpress | |
} | |
# несколько фиксированных URL, которые надо сразу передать в wordpress мимо Yii | |
# блог | |
# http://icons8.com/blog/??? | |
location ^~ /blog/ { | |
proxy_pass http://wordpress_upstream; | |
} | |
# страницы блога http://icons8.com/2014/01/21/??? | |
# страницы блога http://icons8.com/2014/01/??? | |
location ~ /\d\d\d\d/\d\d/ { | |
proxy_pass http://wordpress_upstream; | |
} | |
# теги http://icons8.com/tag/tool/page/2/ | |
location ^~ /tag/ { | |
proxy_pass http://wordpress_upstream; | |
} | |
# стили и оформление | |
# http://icons8.com/wp-content/themes/icons8/style.css | |
# http://icons8.com/wp-content/themes/icons8/images/layout/dropdown-bg.png | |
# http://icons8.com/wp-content/uploads/2013/10/favicon.ico | |
location ^~ /wp-(.+) { | |
proxy_pass http://wordpress_upstream; | |
} | |
# новостные ленты RSS Atom | |
# http://icons8.com/feed/ | |
# http://icons8.com/feed/rss/ | |
# http://icons8.com/feed/atom/ | |
location ^~ /feed/ { | |
proxy_pass http://wordpress_upstream; | |
} | |
# XML-RPC | |
# http://icons8.com/xmlrpc.php | |
location /xmlrpc.php { | |
proxy_pass http://wordpress_upstream; | |
} | |
# sitemap.xml.gz | |
# http://icons8.com/sitemap.xml.gz | |
location ~ /sitemap\.xml\.gz { | |
proxy_pass http://wordpress_upstream; | |
} | |
# prevent nginx from serving dotfiles (.htaccess, .svn, .git, etc.) | |
location ~ /\. { | |
deny all; | |
access_log off; | |
log_not_found off; | |
} | |
} | |
# Приложение wordpress | |
upstream wordpress_upstream { | |
server blog; # тут либо IP либо адрес сервера | |
} | |
# приложение на Yii - конфиг стандартный кроме порта 8889 | |
server { | |
listen 8889; | |
#error_log /var/log/icons8.com/app-error.log; | |
#access_log /var/log/icons8.com/app-access.log; | |
charset utf-8; | |
set $yii_bootstrap "index.php"; | |
fastcgi_intercept_errors on; # в случае ошибок (в частности, 404 Page Not Found) обрабатывать их в nginx, а не в приложении | |
root /var/www/icons8.com/www; | |
location / { | |
index index.html $yii_bootstrap; | |
try_files $uri $uri/ /$yii_bootstrap?$args; | |
} | |
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 | |
location ~ \.php { | |
fastcgi_split_path_info ^(.+\.php)(.*)$; | |
#let yii catch the calls to unexising PHP files | |
set $fsn /$yii_bootstrap; | |
if (-f $document_root$fastcgi_script_name){ | |
set $fsn $fastcgi_script_name; | |
} | |
# With php5-cgi alone: | |
fastcgi_pass 127.0.0.1:9000; | |
# With php5-fpm: | |
#fastcgi_pass unix:/tmp/php-fastcgi.sock; | |
include fastcgi_params; | |
fastcgi_param SCRIPT_FILENAME $document_root$fsn; | |
#PATH_INFO and PATH_TRANSLATED can be omitted, but RFC 3875 specifies them for CGI | |
fastcgi_param PATH_INFO $fastcgi_path_info; | |
fastcgi_param PATH_TRANSLATED $document_root$fsn; | |
} | |
# avoid processing of calls to unexisting static files by yii | |
location ~ \.(js|css|png|jpg|gif|swf|ico)$ { | |
root /var/www/icons8.com/www/static; | |
rewrite /static/(.+)$ /$1; # URL /js/help.js is the same as /static/js/help.js | |
access_log off; # do not write logs | |
expires 30d; # client caching for 30 days | |
try_files $uri =404; # взять или вернуть 404 - тогда запросится из wordpress | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment