Nginx: Difference between revisions

Jump to navigation Jump to search
2,112 bytes added ,  14 March 2022
Added example.
imported>Sjwhitak
(Add syntax highlighting.)
imported>Sjwhitak
(Added example.)
 
You want to run a blog that hosts static pages and a wiki that runs [https://www.mediawiki.org/wiki/MediaWiki mediawiki].
 
Here's the steps you'd take with a fresh system (everything run as root):
 
<syntaxhighlight lang="bash">
apt install nginx php7.4 php7.4-fpm git
</syntaxhighlight>
 
Make sure you get the php version that's most recent or the one that's used by whatever software you're trying to use. This example uses version 7.4.
 
Then, make your folders and grab your content:
<syntaxhighlight lang="bash" line>
mkdir /var/www/wiki; cd /var/www/wiki
git clone https://github.com/wikimedia/mediawiki .
mkdir /var/www/blog; cd /var/www/blog
echo "Here's all my blog files" > index.html
</syntaxhighlight>
Configure `nginx` to point at these files, edit `/etc/nginx/sites-enabled/sites.conf`:
<syntaxhighlight lang="nginx">
server {
root /var/www/blog;
index index.html;
server_name blog.example.com;
listen 80;
listen [::]:80;
}
server {
root /var/www/mediawiki;
index index.php;
server_name wiki.example.com;
listen 80;
listen [::]:80;
location ~ \.php {
try_files $uri = 404;
fastcgi_pass 127.0.0.1:7777;
fastcgi_index index.php;
include fastcgi_params;
include fastcgi.conf;
}
}
</syntaxhighlight>
Please note that specifically with mediawiki, there are more configurations typically added, like denying access to deleted images, cached files, etc. To do that, paste your URL to: [https://shorturls.redwerks.org/ shortURLs] and step through their given configuration. Finally, mediawiki uses [[mysql]] to run a database, though this is explained when you follow the [https://www.mediawiki.org/wiki/Manual:Installation_guide installation guide].
 
At this point, we have nginx pointing to port `7777` for our `fastcgi` server to run the php files. We need to configure `fpm` to do this:
<syntaxhighlight lang="bash">
vim /etc/php/7.4/fpm/pool.d/www.conf
</syntaxhighlight>
and write
<syntaxhighlight lang="text" line start="36">
listen = 127.0.0.1:7777
</syntaxhighlight>
 
Update everything with systemd,
<syntaxhighlight lang="bash">
systemctl restart nginx
systemctl restart php7.4-fpm
</syntaxhighlight>
and the two sites should work.
Anonymous user

Navigation menu