Skip to content

Commit 2f74577

Browse files
committed
Add instruction to start nginx, close raspberrypi#136
1 parent f31bdec commit 2f74577

File tree

1 file changed

+31
-17
lines changed

1 file changed

+31
-17
lines changed

remote-access/web-server/nginx.md

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Setting up an NGINX web server on a Raspberry Pi
22

3-
NGINX [engine x] is a popular lightweight web server application you can install on the Raspberry Pi to allow it to serve web pages.
3+
NGINX (pronounced *engine x*) is a popular lightweight web server application you can install on the Raspberry Pi to allow it to serve web pages.
44

55
Like Apache, NGINX can serve HTML files over HTTP, and with additional modules can serve dynamic web pages using scripting languages such as PHP.
66

@@ -12,14 +12,19 @@ First install the `nginx` package by typing the following command in to the Term
1212
sudo apt-get install nginx
1313
```
1414

15+
and start the server with:
16+
17+
```bash
18+
sudo /etc/init.d/nginx start
19+
```
20+
1521
## Test the web server
1622

1723
By default, NGINX puts a test HTML file in the web folder. This default web page is served when you browse to `http://localhost/` on the Pi itself, or `http://192.168.1.10` (whatever the Pi's IP address is) from another computer on the network. To find the Pi's IP address, type `hostname -I` at the command line (or read more about finding your [IP address](../../troubleshooting/hardware/networking/ip-address.md)).
1824

1925
Browse to the default web page either on the Pi or from another computer on the network and you should see the following:
2026

2127
![NGINX welcome page](images/nginx-welcome.png)
22-
2328

2429
### Changing the default web page
2530

@@ -40,21 +45,29 @@ sudo nano sites-enabled/default
4045
```
4146

4247
find the line
43-
`index index.html index.htm;`
44-
roughly around line 25 (Press `CTRL-C` in nano to see the current line number)
48+
```
49+
index index.html index.htm;
50+
```
51+
52+
roughly around line 25 (Press `CTRL + C` in nano to see the current line number)
4553

46-
Add `index.php` after `index` to look like this:
47-
`index index.php index.html index.htm;`
54+
Add `index.php` after `index` to look like this:
55+
56+
```
57+
index index.php index.html index.htm;
58+
```
4859

4960
Scroll down until you find a section with the following content:
50-
```bash
61+
62+
```
5163
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
5264
#
5365
# location ~ \.php$ {
5466
```
5567

5668
Edit by removing the `#` characters on the following lines:
57-
```bash
69+
70+
```
5871
location ~ \.php$ {
5972
fastcgi_split_path_info ^(.+\.php)(/.+)$;
6073
fastcgi_pass unix:/var/run/php5-fpm.sock;
@@ -65,7 +78,8 @@ location ~ \.php$ {
6578
```
6679

6780
It should look like this:
68-
```bash
81+
82+
```
6983
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
7084
#
7185
location ~ \.php$ {
@@ -79,26 +93,26 @@ It should look like this:
7993
fastcgi_index index.php;
8094
include fastcgi_params;
8195
}
82-
8396
```
97+
8498
### Test PHP
8599

86-
Move `index.html` to `index.php`
100+
Rename `index.html` to `index.php`:
87101

88102
```bash
89-
sudo mv /usr/share/nginx/www/index.html /usr/share/nginx/www/index.php
103+
cd /usr/share/nginx/www/
104+
sudo mv index.html index.php
90105
```
91106

92-
Edit `index.php`
107+
Open `index.php` for with a text editor:
108+
93109
```bash
94-
cd /usr/share/nginx/www/
95110
sudo nano index.php
96111
```
97112

98113
Add some dynamic PHP content by replacing the current content:
99-
```bash
100-
<? echo phpinfo();
114+
```php
115+
<? echo phpinfo(); ?>
101116
```
102117

103118
Save and refresh your browser. You should see a page with the PHP version, logo and current configuration settings.
104-

0 commit comments

Comments
 (0)