Skip to content

Commit f9d80ae

Browse files
bash command
1 parent 1d89eae commit f9d80ae

File tree

1 file changed

+65
-65
lines changed

1 file changed

+65
-65
lines changed

_posts/2024-11-07-nginx.md

+65-65
Original file line numberDiff line numberDiff line change
@@ -53,40 +53,40 @@ To set up NGINX on your server, follow these steps (using an Ubuntu server as an
5353

5454
1. Install NGINX:
5555

56-
---
57-
sudo apt update
58-
sudo apt install nginx
59-
---
56+
```bash
57+
sudo apt update
58+
sudo apt install nginx
59+
```
6060

6161
2. Set Up Basic Configuration:
6262

6363
- Open the configuration file:
6464

65-
---
65+
```bash
6666
sudo nano /etc/nginx/sites-available/default
67-
---
67+
```
6868

6969
- Enter the following basic configuration:
7070

71-
---
72-
server {
73-
listen 80;
74-
server_name example.com;
75-
76-
location / {
77-
root /var/www/html;
78-
index index.html;
79-
}
71+
```nginx
72+
server {
73+
listen 80;
74+
server_name example.com;
75+
76+
location / {
77+
root /var/www/html;
78+
index index.html;
8079
}
81-
---
80+
}
81+
```
8282

8383
3. Start NGINX:
8484

8585
- After making your changes, start NGINX:
8686

87-
---
88-
sudo systemctl restart nginx
89-
---
87+
```bash
88+
sudo systemctl restart nginx
89+
```
9090

9191
4. Test:
9292

@@ -101,96 +101,96 @@ NGINX is an incredibly powerful, fast, and efficient tool for managing web traff
101101

102102
- Stopping NGINX
103103

104-
---
105-
sudo systemctl stop nginx
106-
---
104+
```bash
105+
sudo systemctl stop nginx
106+
```
107107

108108
- Restarting NGINX
109109

110-
---
111-
sudo systemctl restart nginx
112-
---
110+
```bash
111+
sudo systemctl restart nginx
112+
```
113113

114114
- Reloading NGINX Configuration
115115

116-
---
117-
sudo systemctl reload nginx
118-
---
116+
```bash
117+
sudo systemctl reload nginx
118+
```
119119

120120
- Checking the Status of NGINX
121121

122-
---
123-
sudo systemctl status nginx
124-
---
122+
```bash
123+
sudo systemctl status nginx
124+
```
125125

126-
- Enabling NGINX on Startup
126+
- Enabing NGINX on Startup
127127

128-
---
129-
sudo systemctl enable nginx
130-
---
128+
```bash
129+
sudo systemctl enable nginx
130+
```
131131

132132
- Disabling NGINX on Startup
133133

134-
---
135-
sudo systemctl disable nginx
136-
---
134+
```bash
135+
sudo systemctl disable nginx
136+
```
137137

138138
- Testing the Configuration for Errors
139139

140-
---
141-
sudo nginx -t
142-
---
140+
```bash
141+
sudo nginx -t
142+
```
143143

144144
- Running NGINX as a Background Process
145145

146-
---
147-
sudo nginx
148-
---
146+
```bash
147+
sudo nginx
148+
```
149149

150150
- Stopping NGINX without systemd
151151

152-
---
153-
sudo nginx -s stop
154-
---
152+
```bash
153+
sudo nginx -s stop
154+
```
155155

156156
- Reloading Configuration without Stopping NGINX
157157

158-
---
159-
sudo nginx -s reload
160-
---
158+
```bash
159+
sudo nginx -s reload
160+
```
161161

162162
- Checking Logs
163163

164164
Access error or access logs to diagnose issues. On Ubuntu, logs are typically located at /var/log/nginx/.
165165
- Error log:
166166

167-
---
168-
tail -f /var/log/nginx/error.log
169-
---
167+
```bash
168+
tail -f /var/log/nginx/error.log
169+
```
170170

171171
- Access log:
172172

173-
---
174-
tail -f /var/log/nginx/access.log
175-
---
173+
```bash
174+
tail -f /var/log/nginx/access.log
175+
```
176176

177177
- Running in Foreground (without systemd)
178178

179-
---
180-
sudo nginx -g "daemon off;"
181-
---
179+
```bash
180+
sudo nginx -g "daemon off;"
181+
```
182182

183183
- Gracefully Shutting Down NGINX
184184
- Shuts down NGINX from the command line without systemctl.
185185

186-
---
187-
sudo nginx -s quit
188-
---
186+
```bash
187+
sudo nginx -s quit
188+
```
189189

190190
- Reopening Log Files
191191

192-
---
193-
sudo nginx -s reopen
194-
---
192+
```bash
193+
sudo nginx -s reopen
194+
```
195195

196196
These commands cover the basics for managing NGINX on a Linux server, including routine maintenance, restarting, testing configurations, and checking the server’s status.

0 commit comments

Comments
 (0)