You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _posts/2024-11-07-nginx.md
+65-65
Original file line number
Diff line number
Diff line change
@@ -53,40 +53,40 @@ To set up NGINX on your server, follow these steps (using an Ubuntu server as an
53
53
54
54
1. Install NGINX:
55
55
56
-
---
57
-
sudo apt update
58
-
sudo apt install nginx
59
-
---
56
+
```bash
57
+
sudo apt update
58
+
sudo apt install nginx
59
+
```
60
60
61
61
2. Set Up Basic Configuration:
62
62
63
63
- Open the configuration file:
64
64
65
-
---
65
+
```bash
66
66
sudo nano /etc/nginx/sites-available/default
67
-
---
67
+
```
68
68
69
69
- Enter the following basic configuration:
70
70
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;
80
79
}
81
-
---
80
+
}
81
+
```
82
82
83
83
3. Start NGINX:
84
84
85
85
- After making your changes, start NGINX:
86
86
87
-
---
88
-
sudo systemctl restart nginx
89
-
---
87
+
```bash
88
+
sudo systemctl restart nginx
89
+
```
90
90
91
91
4. Test:
92
92
@@ -101,96 +101,96 @@ NGINX is an incredibly powerful, fast, and efficient tool for managing web traff
101
101
102
102
- Stopping NGINX
103
103
104
-
---
105
-
sudo systemctl stop nginx
106
-
---
104
+
```bash
105
+
sudo systemctl stop nginx
106
+
```
107
107
108
108
- Restarting NGINX
109
109
110
-
---
111
-
sudo systemctl restart nginx
112
-
---
110
+
```bash
111
+
sudo systemctl restart nginx
112
+
```
113
113
114
114
- Reloading NGINX Configuration
115
115
116
-
---
117
-
sudo systemctl reload nginx
118
-
---
116
+
```bash
117
+
sudo systemctl reload nginx
118
+
```
119
119
120
120
- Checking the Status of NGINX
121
121
122
-
---
123
-
sudo systemctl status nginx
124
-
---
122
+
```bash
123
+
sudo systemctl status nginx
124
+
```
125
125
126
-
-Enabling NGINX on Startup
126
+
-Enabing NGINX on Startup
127
127
128
-
---
129
-
sudo systemctl enable nginx
130
-
---
128
+
```bash
129
+
sudo systemctl enable nginx
130
+
```
131
131
132
132
- Disabling NGINX on Startup
133
133
134
-
---
135
-
sudo systemctl disable nginx
136
-
---
134
+
```bash
135
+
sudo systemctl disable nginx
136
+
```
137
137
138
138
- Testing the Configuration for Errors
139
139
140
-
---
141
-
sudo nginx -t
142
-
---
140
+
```bash
141
+
sudo nginx -t
142
+
```
143
143
144
144
- Running NGINX as a Background Process
145
145
146
-
---
147
-
sudo nginx
148
-
---
146
+
```bash
147
+
sudo nginx
148
+
```
149
149
150
150
- Stopping NGINX without systemd
151
151
152
-
---
153
-
sudo nginx -s stop
154
-
---
152
+
```bash
153
+
sudo nginx -s stop
154
+
```
155
155
156
156
- Reloading Configuration without Stopping NGINX
157
157
158
-
---
159
-
sudo nginx -s reload
160
-
---
158
+
```bash
159
+
sudo nginx -s reload
160
+
```
161
161
162
162
- Checking Logs
163
163
164
164
Access error or access logs to diagnose issues. On Ubuntu, logs are typically located at /var/log/nginx/.
165
165
- Error log:
166
166
167
-
---
168
-
tail -f /var/log/nginx/error.log
169
-
---
167
+
```bash
168
+
tail -f /var/log/nginx/error.log
169
+
```
170
170
171
171
- Access log:
172
172
173
-
---
174
-
tail -f /var/log/nginx/access.log
175
-
---
173
+
```bash
174
+
tail -f /var/log/nginx/access.log
175
+
```
176
176
177
177
- Running in Foreground (without systemd)
178
178
179
-
---
180
-
sudo nginx -g "daemon off;"
181
-
---
179
+
```bash
180
+
sudo nginx -g "daemon off;"
181
+
```
182
182
183
183
- Gracefully Shutting Down NGINX
184
184
- Shuts down NGINX from the command line without systemctl.
185
185
186
-
---
187
-
sudo nginx -s quit
188
-
---
186
+
```bash
187
+
sudo nginx -s quit
188
+
```
189
189
190
190
- Reopening Log Files
191
191
192
-
---
193
-
sudo nginx -s reopen
194
-
---
192
+
```bash
193
+
sudo nginx -s reopen
194
+
```
195
195
196
196
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