Answer the question
In order to leave comments, you need to log in
How to configure nginx proxy_pass for https so that Laravel does the right routes?
There is an application on Laravel, there was a need to make caching (including php-fpm data).
The configuration is like this:
server {
listen 80;
server_name mydomain.ru;
return 301 https://mydomain.ru$request_uri;
return 404;
}
server {
listen 443 ssl;
server_name mydomain.ru;
location / {
proxy_pass http://127.0.0.1:5443/;
proxy_cache all;
proxy_cache_valid any 1h;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_redirect off;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
ssl_certificate /etc/letsencrypt/live/mydomain.ru/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/mydomain.ru/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
listen 5443;
server_name mydomain.ru;
root /home/mydomain/site/public;
index index.php;
location ~* ^.+\.(rss|atom|jpg|jpeg|gif|png|ico|rtf|js|css|webp|webm|woff2|svg)$ {
expires max;
}
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi.conf;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_cache fcgi;
fastcgi_cache_valid 200 60m;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
}
}
Answer the question
In order to leave comments, you need to log in
This helped:
In the server.location block:
location / {
proxy_cache all;
proxy_cache_valid any 1h;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header HTTPS YES;
proxy_pass http://127.0.0.1:5443/;
}
# параметры https
fastcgi_param HTTPS on;
fastcgi_param HTTP_HTTPS on;
fastcgi_param REQUEST_SCHEME https;
fastcgi_param SERVER_PORT 443;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question