Nginx on Windows
If you’re using Nginx on Windows, here’s how you can get started:
1. Download Nginx
- Go to the official Nginx download page.
- Download the latest stable version for Windows (e.g.,
nginx-x.x.x.zip
).
2. Install Nginx
- Extract the downloaded ZIP file to a folder, such as
C:\nginx
. - Open the
nginx
folder. You’ll see a structure like this:C:\nginx├── conf├── html├── logs└── nginx.exe
3. Start Nginx
- Open a Command Prompt or PowerShell.
- Navigate to the Nginx directory:
Terminal window cd C:\nginx - Start Nginx:
Terminal window nginx.exe
- Nginx should now be running. Open your browser and go to
http://localhost
. You should see the default Nginx welcome page.
4. Basic Configuration
The main configuration file is conf\nginx.conf
in the Nginx directory.
-
Open the configuration file in a text editor:
Terminal window notepad C:\nginx\conf\nginx.conf -
Modify it to suit your needs. For example, to set up a basic website:
server {listen 80;server_name localhost;root C:/nginx/html;index index.html;location / {try_files $uri $uri/ =404;}} -
Save the file and reload Nginx:
Terminal window nginx.exe -s reload
5. Create Your Website
- Place your HTML files in the
html
folder:- For example:
C:\nginx\html\index.html
.
- For example:
- Access your site at
http://localhost
.
6. Stop Nginx
To stop Nginx:
nginx.exe -s stop
7. Run Nginx as a Windows Service (Optional)
Running Nginx as a service ensures it starts automatically with Windows.
- Use a tool like NSSM (Non-Sucking Service Manager) to register Nginx as a service. Download NSSM from https://nssm.cc/.
- Install the service:
Terminal window nssm install nginx - Configure the application path to
C:\nginx\nginx.exe
.
If you need help with a specific Nginx setup, feel free to ask!