Я установил сервер Amazon ec2 LEMP для своего веб-сайта с фотографиями, который раньше был на apache, с которым я гораздо лучше знаком.
У меня в целом все работает нормально, Кроме для в каталоге блога. Кажется, что файлы CSS и JS обслуживаются PHP и имеют тип содержимого text / html, например, вот заголовки ответов для таблицы стилей моей темы (/blog/wp-content/themes/twentyseventeen/style.css?ver=4.9.8
):
content-type: text/html
date: Fri, 26 Oct 2018 02:33:26 GMT
server: nginx/1.12.2
status: 200
x-powered-by: PHP/5.4.16
против заголовков для моей собственной таблицы стилей (/include/css/style.css
):
accept-ranges: bytes
cache-control: max-age=315360000
content-length: 34199
content-type: text/css
date: Fri, 26 Oct 2018 02:48:04 GMT
etag: "5b7f653b-8597"
expires: Thu, 31 Dec 2037 23:55:55 GMT
last-modified: Fri, 24 Aug 2018 01:54:03 GMT
server: nginx/1.12.2
status: 200
Я прочитал множество тем, посвященных очень похожим проблемам. Однако я сбит с толку, потому что моя проблема ограничивается /blog/
каталог.
Несколько других вопросов / ответов, которые я прочитал, упомянуты security.limit_extensions
и действительно мой (/etc/php-fpm.d/www.conf
) был настроен так:
security.limit_extensions =
;security.limit_extensions = .php .php3 .php4 .php5 .ttf
Я изменил это:
;security.limit_extensions =
security.limit_extensions = .php .php3 .php4 .php5 .ttf
и перезапустили nginx через service nginx restart
- но проблема все еще сохраняется ..
Не представляю, чего мне не хватает .. Готов бросить полотенце и снова переключиться на apache .. :(
Кто-нибудь видит, что я пропустил?
ОБНОВЛЕНИЕ: файлы конфигурации
/etc/nginx/nginx.conf:
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
#user ec2-user;
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
server_names_hash_bucket_size 64;
client_max_body_size 2M;
include mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
/etc/nginx/sites-available/mikewillisphotography.com.conf
server {
listen 80 default_server;
server_name www.mikewillisphotography.com mikewillisphotography.com;
return 301 https://www.mikewillisphotography.com$request_uri;
}
server {
listen 443 ssl http2;
server_name mikewillisphotography.com;
return 301 https://www.mikewillisphotography.com$request_uri;
}
server {
listen 443 ssl default_server;
server_name www.mikewillisphotography.com;
#server_name localhost;
include /etc/nginx/sites-available/includes/restrictions.conf;
include /etc/nginx/sites-available/includes/wordpress.conf;
# include /etc/nginx/sites-available/includes/php.conf;
ssl_certificate /etc/letsencrypt/live/mikewillisphotography.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mikewillisphotography.com/privkey.pem;
location /.well-known/acme-challenge {
#root /var/www/html/letsencrypt/wordpress/;
root /usr/share/nginx/sites/mikewillisphotography.com/htdocs/letsencrypt/wordpress/;
}
client_max_body_size 2M;
# note that these lines are originally from the "location /" block
root /usr/share/nginx/sites/mikewillisphotography.com/htdocs;
index index.php index.html index.htm;
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/sites/mikewillisphotography.com/htdocs;
}
location ~ \.php$ {
include /etc/nginx/sites-available/includes/php.conf;
}
}
/etc/nginx/sites-available/includes/php.conf
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
#wordpress stuff
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include fastcgi.conf;
fastcgi_intercept_errors on;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
/etc/nginx/sites-available/includes/wordpress.conf
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
location ^~ /blog {
root /usr/share/nginx/sites/mikewillisphotography.com/htdocs;
index index.php index.html index.htm;
include /etc/nginx/sites-available/includes/php.conf;
rewrite /wp-admin$ $scheme://$host$uri/index.php?q=$1 permanent;
try_files $uri $uri/ @blog;
}
location @blog {
rewrite ^/blog(.*) /blog/index.php?q=$1;
}
Я обнаружил проблему - я не проверял файл wordpress.conf и, конечно же, он включал файл php.conf для каждого запроса в /blog/
каталог.
location ^~ /blog {
root /usr/share/nginx/sites/mikewillisphotography.com/htdocs;
index index.php index.html index.htm;
include /etc/nginx/sites-available/includes/php.conf;
rewrite /wp-admin$ $scheme://$host$uri/index.php?q=$1 permanent;
try_files $uri $uri/ @blog;
}
Я изменил его, чтобы использовать вложенный блок местоположения для перехвата файлов .php, что решило проблему. Не уверен, что это самый эффективный метод, но он работает.
location ^~ /blog {
root /usr/share/nginx/sites/mikewillisphotography.com/htdocs;
index index.php index.html index.htm;
rewrite /wp-admin$ $scheme://$host$uri/index.php?q=$1 permanent;
try_files $uri $uri/ @blog;
location ~ \.php$ {
include /etc/nginx/sites-available/includes/php.conf;
}
}