У меня есть проксирование nginx на apache в качестве бэкэнда, чтобы nginx мог обрабатывать статические активы. К сожалению, когда я пытаюсь посетить «красивый URL», он просто отображает страницу индекса.
конфигурация nginx
server {
listen 80;
root /var/www/example.com;
index index.php index.html index.htm;
server_name example.com www.example.com a.example.com b.example.com c.example.com;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8080;
}
location ~ /\.ht {
deny all;
}
}
Конфигурация Apache vhost
<VirtualHost 127.0.0.1:8080>
ServerName example.com
ServerAlias www.example.com
ServerAlias a.example.com
ServerAlias b.example.com
ServerAlias c.example.com
ServerAdmin info@example.com
DocumentRoot /var/www/example.com
<Directory /var/www/example.com>
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/5r_error.log
CustomLog ${APACHE_LOG_DIR}/5r_access.log combined
</VirtualHost>
.htaccess
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}/maintenance.html -f
RewriteCond %{REQUEST_FILENAME} !/maintenance.html
RewriteRule ^.*$ /maintenance.html [L]
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http%2://%1%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^example-old.co.uk [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example-old.co.uk [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteRule ^servers/([^\/]+)/?$ servers.php?scroll-to-server=$1 [L,QSA]
RewriteRule ^media/([0-9]+)$ media.php?media-id=$1 [L,QSA]
RewriteRule ^media/([a-z,]+)$ media.php?filter=$1 [L,QSA]
RewriteRule ^manage/?([^\/]+)$ admin.php?page=$1 [L,QSA]
RewriteRule ^operations/?([^/]*)(.*)$ operations.php?c=$1&m=$2 [L,QSA]
ErrorDocument 404 /error
ErrorDocument 403 /error
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^.]+)$ $1.php [NC,L]
Когда я приезжаю example.com
загружается нормально, когда я навещаю example.com/test
он просто показывает домашнюю страницу. Запрос в Chrome для страницы возвращает 200.
Ваш try_files
изменяет URL на /index.php
чтобы отправить его вверх, что теряет красивая постоянная ссылка.
Вы можете попробовать отправить красивая постоянная ссылка вверх по течению, добавив именованное местоположение. Может быть:
location / {
try_files $uri $uri/ @proxy;
}
location @proxy {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8080;
}
location ~ \.php$ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8080;
}