|
1 | | -# Default server definition |
| 1 | +# Nginx config for Laravel Octane (proxy mode) |
| 2 | +map $http_upgrade $connection_upgrade { |
| 3 | + default upgrade; |
| 4 | + '' close; |
| 5 | +} |
| 6 | + |
2 | 7 | server { |
3 | | - listen [::]:80 default_server; |
4 | 8 | listen 80 default_server; |
| 9 | + listen [::]:80 default_server; |
5 | 10 | server_name _; |
6 | 11 |
|
7 | 12 | sendfile off; |
8 | 13 | tcp_nodelay on; |
9 | 14 | absolute_redirect off; |
10 | 15 |
|
11 | | - root /var/www/html; |
| 16 | + root /var/www/html/public; |
12 | 17 | index index.php index.html; |
13 | 18 |
|
| 19 | + charset utf-8; |
| 20 | + |
| 21 | + # Proxy all requests to Laravel Octane |
14 | 22 | location / { |
15 | | - # First attempt to serve request as file, then |
16 | | - # as directory, then fall back to index.php |
17 | | - try_files $uri $uri/ /index.php?q=$uri&$args; |
| 23 | + proxy_pass http://control-panel:8000; |
| 24 | + proxy_set_header Host $host; |
| 25 | + proxy_set_header X-Real-IP $remote_addr; |
| 26 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 27 | + proxy_set_header X-Forwarded-Proto $scheme; |
| 28 | + proxy_http_version 1.1; |
| 29 | + proxy_set_header Upgrade $http_upgrade; |
| 30 | + proxy_set_header Connection $connection_upgrade; |
| 31 | + proxy_read_timeout 60; |
| 32 | + proxy_send_timeout 60; |
18 | 33 | } |
19 | 34 |
|
20 | | - # Redirect server error pages to the static page /50x.html |
21 | | - error_page 500 502 503 504 /50x.html; |
22 | | - location = /50x.html { |
23 | | - root /var/lib/nginx/html; |
| 35 | + # Serve static assets directly |
| 36 | + location ~* \.(jpg|jpeg|gif|png|css|js|ico|svg|woff|woff2|ttf|eot|xml)$ { |
| 37 | + root /var/www/html/public; |
| 38 | + expires 30d; |
| 39 | + add_header Cache-Control "public, immutable"; |
| 40 | + try_files $uri @octane; |
24 | 41 | } |
25 | 42 |
|
26 | | - # Pass the PHP scripts to PHP-FPM listening on php-fpm.sock |
27 | | - location ~ \.php$ { |
28 | | - try_files $uri =404; |
29 | | - fastcgi_split_path_info ^(.+\.php)(/.+)$; |
30 | | - fastcgi_pass unix:/run/php-fpm.sock; |
31 | | - fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; |
32 | | - fastcgi_index index.php; |
33 | | - include fastcgi_params; |
| 43 | + location @octane { |
| 44 | + proxy_pass http://control-panel:8000; |
| 45 | + proxy_set_header Host $host; |
| 46 | + proxy_set_header X-Real-IP $remote_addr; |
| 47 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 48 | + proxy_set_header X-Forwarded-Proto $scheme; |
34 | 49 | } |
35 | 50 |
|
36 | | - # Set the cache-control headers on assets to cache for 5 days |
37 | | - location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ { |
38 | | - expires 5d; |
| 51 | + # Redirect server error pages |
| 52 | + error_page 500 502 503 504 /50x.html; |
| 53 | + location = /50x.html { |
| 54 | + root /var/lib/nginx/html; |
39 | 55 | } |
40 | 56 |
|
41 | | - # Deny access to . files, for security |
| 57 | + # Deny access to hidden files |
42 | 58 | location ~ /\. { |
43 | 59 | log_not_found off; |
44 | 60 | deny all; |
45 | 61 | } |
46 | | - |
47 | | - # Allow fpm ping and status from localhost |
48 | | - location ~ ^/(fpm-status|fpm-ping)$ { |
49 | | - access_log off; |
50 | | - allow 127.0.0.1; |
51 | | - deny all; |
52 | | - fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; |
53 | | - include fastcgi_params; |
54 | | - fastcgi_pass unix:/run/php-fpm.sock; |
55 | | - } |
56 | 62 | } |
0 commit comments