메이커링크

Nginx 설정 문법 검사 후 자동 Reload: Cursor 명령어 레시피

Nginx 설정 파일 문법 오류를 검사하고, 오류가 없을 경우 자동으로 설정을 리로드하는 Cursor 명령어 레시피입니다. 배포 전 설정 오류를 빠르게 확인하고 적용할 때 유용합니다.

#nginx#설정#문법검사#reload#배포

Nginx 설정 문법 검사 및 자동 Reload 레시피

이 레시피는 Nginx 설정 파일의 문법 오류를 확인하고, 오류가 없을 경우 Nginx 설정을 안전하게 리로드하는 과정을 자동화합니다. Cursor 에디터 환경에서 바로 사용할 수 있도록 설계되었습니다.

언제 사용하나요?
  • Nginx 설정을 변경한 후, 배포 전에 반드시 문법 오류를 검증하고 싶을 때
  • 설정 파일 오류로 인한 서비스 중단을 최소화하고 싶을 때
  • 반복적인 Nginx 설정 검증 및 적용 과정을 효율화하고 싶을 때
주요 기능
  1. Nginx 설정 문법 검사: nginx -t 명령어를 사용하여 현재 Nginx 설정 파일의 문법적 유효성을 검사합니다.
  2. 오류 발생 시 알림: 문법 검사에서 오류가 발견되면, 사용자에게 명확하게 오류 내용을 알리고 설정을 리로드하지 않습니다.
  3. 성공 시 자동 Reload: 문법 검사가 성공적으로 완료되면, systemctl reload nginx 또는 nginx -s reload 명령어를 사용하여 Nginx 설정을 안전하게 리로드합니다.
사용 방법

Cursor 에디터에서 .cursor/rules/nginx_reload.mdc 와 같은 이름으로 파일을 생성하고 아래 내용을 복사하여 붙여넣으세요.

You are an expert Nginx administrator and deployment assistant using the Cursor IDE.

When editing or running commands related to Nginx configuration:

1.  **Prioritize Safety and Verification**: Before applying any Nginx configuration changes, always perform a syntax check.
2.  **Utilize `nginx -t`**: Use the `nginx -t` command to validate the Nginx configuration syntax.
3.  **Automate Reload on Success**: If `nginx -t` reports successful syntax validation, proceed to reload the Nginx service gracefully.
4.  **Inform User of Errors**: If `nginx -t` reports syntax errors, clearly inform the user about the errors and **do not** proceed with the reload.

**Workflow for Nginx Configuration Changes:**

*   **Step 1: Detect Configuration File Changes**
    *   When you have finished editing an Nginx configuration file (e.g., `/etc/nginx/nginx.conf` or files within `/etc/nginx/conf.d/` or `/etc/nginx/sites-available/`), the system should be ready to prompt for verification.

*   **Step 2: Execute Syntax Check**
    *   The system will automatically run the command: `sudo nginx -t`
    *   **Analysis of `nginx -t` Output:**
        *   **If `nginx -t` output contains "syntax is ok" and "test is successful"**: Proceed to Step 3.
        *   **If `nginx -t` output contains "syntax error" or "test failed"**: 
            *   Display the full error output to the user.
            *   Advise the user to fix the reported errors before attempting to reload.
            *   **Do not** proceed with the reload.
            *   Example message: "Nginx configuration syntax error detected. Please review the output below and correct the configuration before reloading.\n\n[Error details from nginx -t]"

*   **Step 3: Graceful Nginx Reload**
    *   If the syntax check in Step 2 was successful, the system will execute a command to gracefully reload the Nginx configuration. Choose **one** of the following common methods based on the target environment:
        *   **Using `systemctl` (Recommended for most modern Linux systems like Ubuntu, CentOS 7+, Debian 8+)**:
            ```bash
            sudo systemctl reload nginx
            ```
            *   Confirm reload success by checking the status: `sudo systemctl status nginx`
        *   **Using `service` (Older SysVinit systems)**:
            ```bash
            sudo service nginx reload
            ```
        *   **Directly using `nginx -s reload` (Common, works on many systems)**:
            ```bash
            sudo nginx -s reload
            ```
    *   **Confirmation**: After executing the reload command, briefly confirm the action was taken. A simple message like "Nginx configuration syntax is OK. Nginx reloaded successfully." is sufficient.

*   **Error Handling**: 
    *   If the reload command itself fails (e.g., due to permissions, incorrect service name), report the failure to the user.

**Example Interaction Flow:**

1.  User saves `/etc/nginx/sites-available/my_site.conf`.
2.  Cursor detects the change and prompts: "Nginx configuration file saved. Perform syntax check and reload?"
3.  User confirms.
4.  System runs `sudo nginx -t`. 
    *   **Scenario A (Success):** Output shows "syntax is ok", "test is successful". System proceeds to run `sudo systemctl reload nginx`. User sees "Nginx configuration syntax 
11
스크랩
27
좋아요

메이커링크 에이전트

이 레시피, 직접 따라 하지 말고 맡겨 보세요

휴대폰에서 한 줄로 지시하면 메이커링크 에이전트가 내 PC의 Cursor · Claude Code로 그대로 실행합니다.

무료로 시작하기 원격 PC 1대 무료 · 내 AI 구독 그대로

함께 보면 좋은 레시피

AI 레시피

Cursor AI를 활용한 코드 리팩토링 및 성능 최적화 가이드

Cursor의 AI 코딩 어시스턴트를 사용하여 코드의 가독성을 높이고, 실행 속도를 개선하며, 메모리 사용량을 줄이는 방법을 단계별로 안내합니다. 코드 품질 향상을 위한 실질적인 팁을 제공합니다.

#code refactoring#performance optimization

터미널 레시피

RESTful API 기본 구조 및 인증 토큰 검증 CLI 레시피

RESTful API의 기본 GET, POST 요청을 보내고, Authorization 헤더에 Bearer 토큰을 포함하여 서버 응답을 확인하는 CLI 명령어입니다. API 개발 및 테스트에 유용합니다.

#curl#restful api

AI 레시피

GitOps 기반 Kubernetes 자동 배포 파이프라인 구축 가이드

GitOps 원칙을 사용하여 Kubernetes 환경에 애플리케이션을 자동으로 배포하고 관리하는 방법을 안내합니다. CI/CD와 Git의 장점을 결합한 효율적인 배포 전략을 이해하고 적용하는 데 도움이 됩니다.

#gitops#kubernetes

터미널 레시피

Helm으로 Kubernetes 애플리케이션 패키징 및 기본 배포

Helm 차트를 생성하고 로컬 Kubernetes 클러스터에 간단한 애플리케이션을 배포하는 과정을 보여주는 명령어 레시피입니다. CI/CD 파이프라인 연동의 기초로 활용할 수 있습니다.

#helm#kubernetes

AI 레시피

SQL vs NoSQL 데이터베이스 비교 및 선택 가이드

SQL과 NoSQL 데이터베이스의 핵심적인 차이점을 이해하고, 프로젝트 요구사항에 맞는 데이터베이스를 선택하는 데 도움을 주는 가이드입니다.

#sql#nosql

AI 레시피

GitOps 핵심 개념과 CI/CD 파이프라인 구축 전략 가이드

GitOps의 기본 원리를 이해하고, Docker, Kubernetes, GitHub Actions를 활용하여 자동화된 CI/CD 파이프라인을 구축하는 방법을 안내합니다. 실무 적용에 필요한 핵심 개념과 전략을 다룹니다.

#gitops#cicd