# Nginx JWT Auth Script - Fixes Applied

## Issues Fixed

### 1. Missing Package Error
**Problem**: Script was trying to install `libnginx-mod-http-lua` which doesn't exist as a separate package in Ubuntu 22.04.

**Fix**: Removed the attempt to install `libnginx-mod-http-lua` separately. The script now:
- Removes `nginx-core` if present
- Installs `nginx-extras` which includes Lua support built-in
- Falls back to regular `nginx` if `nginx-extras` is not available

### 2. Locale Warnings
**Problem**: Multiple locale warnings cluttering the output:
- `perl: warning: Setting locale failed`
- `locale: Cannot set LC_CTYPE to default locale`
- `dpkg-preconfigure: unable to re-open stdin`

**Fix**: Added locale suppression to all command executions:
- Set `export LC_ALL=C` and `export LANG=C` in all bash sessions
- Filtered locale warnings from apt-get output using `grep -vE "(perl: warning|locale:|dpkg-preconfigure)"`

## Changes Made

### Package Installation Section (Lines 42-66)
- Removed attempt to install `libnginx-mod-http-lua`
- Added proper nginx-core removal before installing nginx-extras
- Added locale environment variables
- Added output filtering for locale warnings

### JWT Secret Generation (Lines 68-85)
- Added locale environment variables
- Added output filtering

### Lua Script Creation (Lines 87-135)
- Added locale environment variables at start of heredoc

### Lua Library Installation (Lines 137-174)
- Added locale environment variables at start of heredoc
- Added output filtering for apt-get commands

### Nginx Configuration (Lines 176-389)
- Added locale environment variables at start of heredoc

## Result

The script now:
1. ✅ Installs nginx-extras correctly (which includes Lua support)
2. ✅ Suppresses locale warnings for cleaner output
3. ✅ Handles package installation errors gracefully
4. ✅ Continues with JWT configuration even if some packages have issues

## Testing

After these fixes, the script should:
- Install nginx-extras without errors about missing `libnginx-mod-http-lua`
- Show minimal locale warnings (only critical errors)
- Complete JWT authentication setup successfully

## Notes

- `nginx-extras` includes the Lua module, so no separate package is needed
- Locale warnings are cosmetic and don't affect functionality
- The script will continue even if some non-critical packages fail to install

