Skip to content

Instantly share code, notes, and snippets.

@danielpereirabp
Created June 22, 2018 19:19
Show Gist options
  • Save danielpereirabp/946d7d171352b86c0531fc077c1cb2f3 to your computer and use it in GitHub Desktop.
Save danielpereirabp/946d7d171352b86c0531fc077c1cb2f3 to your computer and use it in GitHub Desktop.
Nginx Proxy - SPA (Vue 2) + API/ADMIN (Laravel 5.6)
server {
listen 80;
server_name domain.com.br;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8181;
}
location ~ ^/(admin|api) {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8282;
}
}
server {
listen 8282;
server_name localhost;
root /var/www/vhosts/projects/nginx-proxy/laravel/public;
index index.php;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fixes timeouts
fastcgi_read_timeout 600;
include fastcgi_params;
}
error_log /var/log/nginx/nginx-proxy-laravel.error.log;
access_log /var/log/nginx/nginx-proxy-laravel.access.log;
}
server {
listen 8181;
root /var/www/vhosts/projects/nginx-proxy/vue/dist;
index index.html;
server_name localhost;
location / {
try_files $uri $uri/ @rewrites;
}
location @rewrites {
rewrite ^(.+)$ /index.html last;
}
location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
# Some basic cache-control for static files to be sent to the browser
expires max;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
}
@dinhtin12
Copy link

you are so good.

@Baha2Odeh
Copy link

thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment