[2024-feb-29] Sad news: Eric Layton aka Nocturnal Slacker aka vtel57 passed away on Feb 26th, shortly after hospitalization. He was one of our Wiki's most prominent admins. He will be missed.

Welcome to the Slackware Documentation Project

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
howtos:hardware:arm:nginx [2020/03/02 18:15 (UTC)] – [Configuring php-fpm.conf] text formatting exagahowtos:hardware:arm:nginx [2020/03/05 12:03 (UTC)] (current) – [Configuring nginx to run on Slackware ARM] added code 'default_server;' exaga
Line 10: Line 10:
 ==== Notes ==== ==== Notes ====
  
-This page will hopefully allow you how run nginx on Slackware ARM successfully, from scratch. There's no reason what-so-ever that the same procedure(s) shouldn't work on Slackware x86_64 [or Slackware ARM 14.2], but for the purpose of testing it has been carried out under Slackware ARM -current [23-26 February 2020]. +This page will hopefully allow you how run nginx on Slackware ARM successfully, from scratch. There's no reason what-so-ever that the same procedure(s) shouldn't work on Slackware x86_64 [or Slackware ARM 14.2], but for the purpose of testing it has been carried out under Slackware ARM -current [23 February - 05 March 2020]. 
  
-Slackware ARM -current was running [kernel 5.4.21] on a Raspberry Pi 4 and used to build the package, install and configure nginx. Any ARM device running Slackware may be used for this purpose. The -current (development) version was chosen as it includes the latest software, etc.+Slackware ARM -current was running [kernel 5.4.22] on a Raspberry Pi 4 and used to build the package, install and configure nginx. Any ARM device running Slackware may be used for this purpose. The -current (development) version was chosen as it includes the latest software, etc.
  
 ==== Requirements ==== ==== Requirements ====
Line 43: Line 43:
 </code> </code>
  
-You also need to download the latest [[http://nginx.org/download/|nginx mainline]] version and put it in the same directory as the SlackBuild files. At the time of writing this guide the latest version was  [[http://nginx.org/download/nginx-1.17.8.tar.gz|nginx-1.17.8]] but it's best to check if an updated version exists.+You also need to download the latest [[http://nginx.org/download/|nginx mainline]] version and put it in the same directory as the SlackBuild files. At the time of writing this guide the latest version was  [[http://nginx.org/download/nginx-1.17.9.tar.gz|nginx-1.17.9]] but it's best to check if an updated version exists.
  
 <code> <code>
-~# wget http://nginx.org/download/nginx-1.17.8.tar.gz+~# wget http://nginx.org/download/nginx-1.17.9.tar.gz
 </code> </code>
  
Line 61: Line 61:
 </code> </code>
  
-... and change it to the version of nginx you have downloaded. For 'nginx-1.17.8+... and change it to the version of nginx you have downloaded. For 'nginx-1.17.9it would be like this:
  
 <code> <code>
-VERSION=${VERSION:-1.17.8}+VERSION=${VERSION:-1.17.9}
 </code> </code>
  
Line 81: Line 81:
 <code> <code>
 ~# time ./nginx.SlackBuild ~# time ./nginx.SlackBuild
 +</code>
 +
 +Alternatively, if you plan on using Maxmind's GeoIP database with 'nginx' then GeoIP support is available as an option. All that's required is the GeoIP package to have been installed first. If you wish to enable GeoIP support in 'nginx' then pass the GEOIP variable to the slackbuild command, like this:
 +
 +<code>
 +~# time GEOIP=yes ./nginx.SlackBuild
 </code> </code>
  
 After a few short minutes, you should see the resulting package in your '/tmp' directory. [NB: if you didn't modify the '${PKGTYPE:-tgz}' variable then the file extension will be '*.tgz' instead of '*.txz'.] Check it like this: After a few short minutes, you should see the resulting package in your '/tmp' directory. [NB: if you didn't modify the '${PKGTYPE:-tgz}' variable then the file extension will be '*.tgz' instead of '*.txz'.] Check it like this:
 +
 +<note>Q. Why do we use 'time' in combination with running the build script? \\
 +A. We like to know how long the process takes. That's all. You don't have to include it in order to be successful.</note>
  
 <code> <code>
 ~# cd /tmp ~# cd /tmp
 ~# ls -lah *.txz ~# ls -lah *.txz
--rw-r--r-- 1 root root 442K Feb 26 06:01 nginx-1.17.8-arm-1_SBo.txz+-rw-r--r-- 1 root root 442K Feb 26 06:01 nginx-1.17.9-arm-1_SBo.txz
 </code> </code>
  
Line 114: Line 123:
  
 <code> <code>
-~# installpkg nginx-1.17.8-arm-1_SBo.txz+~# installpkg nginx-1.17.9-arm-1_SBo.txz
 </code> </code>
  
Line 204: Line 213:
  
     server {     server {
-        listen       80; +        listen       80 default_server
-        server_name  localhost;+        server_name  127.0.0.1 localhost;
  
         location / {         location / {
Line 264: Line 273:
 </code> </code>
  
 +By default 'php-fpm' does not log anything other than startup and shutdown [see: '/var/log/php-fpm.log' after the daemon has been (re)started]. In order to log any relevant error messages we need to make one more change to the file. Find the 'catch_workers_output" section below and uncomment the setting, like this:
  
 +<code>
 +; Redirect worker stdout and stderr into main error log. If not set, stdout and
 +; stderr will be redirected to /dev/null according to FastCGI specs.
 +; Note: on highloaded environement, this can cause some delay in the page
 +; process time (several ms).
 +; Default Value: no
 +catch_workers_output = yes
 +</code>
  
 Save and exit the file. Save and exit the file.
Line 400: Line 418:
  
 GoAccess is very versatile and configurable, and open source. It can parse a great many log formats [logs can be rotated] and can also create static html pages as well as being fully functional in a shell. GoAccess is very versatile and configurable, and open source. It can parse a great many log formats [logs can be rotated] and can also create static html pages as well as being fully functional in a shell.
 +
 +===== Adding additional sites to nginx =====
 +
 +In this guide we've only used one web directory ['/var/www/html'] but in order to expand our single site we're going to add another two sites. This is achieved by adding *.conf files to the '/etc/nginx/conf.d/' directory. You can name them anything you like as long as the file extension is ".conf". For the purposes of this guide we'll configure 'test.local' and 'extra.local' along with our existing 'localhost' site.
 +
 +First we create the '/var/www/test.local' and '/var/www/extra.local' directories where our web content will reside:
 +
 +<code>
 +~# mkdir /var/www/test.local
 +~# mkdir /var/www/extra.local
 +</code>
 +
 +Because we want to use 'test.local' and 'extra.local' as domain name [server_name] aliases we will add the following to our '/etc/hosts' file:
 +
 +<code>
 +# For loopbacking.
 +127.0.0.1               localhost
 +127.0.0.1               myhost.name myhost
 +127.0.0.1               test.local
 +127.0.0.1               extra.local
 +
 +# End of hosts.
 +</code>
 +
 +The above settings will take effect as soon as the file is saved. However, there's nothing there to see yet - because we haven't created it! :-)
 +
 +So, then we create and edit the 'test.local.conf' file:
 +
 +<code>
 +~# nano -w /etc/nginx/conf.d/test.local.conf
 +</code>
 +
 +In this file we need to instruct 'nginx' which server requests it should listen for on a specific port. We need to specify the path/to/the web directory files where this site will be located and we'll also configure the FastCGI server. So we'll enter the following text into this file:
 +
 +<code>
 +server {
 +    listen 80;
 +    server_name test.local;
 +
 +    # this root path is to the webdir
 +    root /var/www/test.local;
 +    
 +    # index pages to load in this order
 +    index index.php index.html index.htm;
 +
 +    #This will be needed for GoAccess ** make sure vcombined map is defined in nginx.conf
 +    access_log /var/log/nginx/access.log vcombined;
 +
 +    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
 +    #
 +    location ~ \.php$ {
 +       root           /var/www/test.local;
 +       fastcgi_pass   127.0.0.1:9000;
 +       fastcgi_index  index.php;
 +       fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
 +       include        fastcgi_params;
 +    }
 +
 +}
 +</code>
 +
 +Again, we are keeping the access_log format in order to make use of web traffic analysis with GoAccess. Save and exit the file when you're happy with the setup.
 +
 +Now we can create and edit the 'extra.local.conf' file in much the same way as the first file:
 +
 +<code>
 +server {
 +    listen 80;
 +    server_name extra.local;
 +
 +    # this root path is to the webdir
 +    root /var/www/extra.local;
 +
 +    # index pages to load in this order
 +    index index.php index.html index.htm;
 +
 +    #This will be needed for GoAccess ** make sure vcombined map is defined in nginx.conf
 +    access_log /var/log/nginx/access.log vcombined;
 +
 +    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
 +    #
 +    location ~ \.php$ {
 +       root           /var/www/extra.local;
 +       fastcgi_pass   127.0.0.1:9000;
 +       fastcgi_index  index.php;
 +       fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
 +       include        fastcgi_params;
 +    }
 +
 +}
 +</code>
 +
 +Note that port:80 is still being used in both cases, as is the existing 'localhost' site, but the server_name and root path are different to reflect that this is a seperate entity. The server_name is how 'nginx' will know which site to direct you to when it is requested. You can of course use other ports. For example, if you required 'test.local' to be accessible on port:1080 then just specify that with a 'listen 1080;' parameter and access it as '<nowiki>http://test.local:1080</nowiki>'
 +
 +The web directories need files in them in order to display any content. So, as before, you could create a simple 'index.php' file and put it in the directory that relates to the new site(s). Or you could crate a simple 'index.html' file to identify the site. For example:
 +
 +<code>
 +~# nano -w /var/www/test.local/index.php
 +
 +<?php 
 +  phpinfo(); 
 +?>
 +</code>
 +
 +And/or...
 +
 +<code>
 +~# echo '<html><body><h1>TEST : It works!</h1></body></html>' > /var/www/test.local/index.html
 +~# echo '<html><body><h1>EXTRA : It works!</h1></body></html>' > /var/www/test.local/index.html
 +</code>
 +
 +When all that's complete, the final task is to test the 'nginx' configuration and restart the daemon.
 +
 +<code>
 +~# nginx -t
 +nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
 +nginx: configuration file /etc/nginx/nginx.conf test is successful
 +~# /etc/rc.d/rc.nginx restart
 +Shutdown Nginx gracefully...
 +Starting Nginx server daemon...
 +</code>
 +
 +So now, to access the new site content on your 'nginx' web server use the following, remembering to request the file you've previously created. For example:
 +
 +<code>
 +~# links http://test.local/index.php
 +~# links http://extra.local/index.html
 +</code>
 +
 +One thing to note is that if you use '<nowiki>http://127.0.0.1/index.html</nowiki>' it will direct you to the 'localhost' site because that has been specified as the default in '/etc/nginx/nginx.conf'. In order to acess the content of any sites other than 'localhost' or '127.0.0.1' [default] the server_name must be used. You can also access the site remotely using the IP address [and port - if specified] of your ARM device instead of a domain name. Or you could add a domain name alias to your 'hosts' file and use that instead. Either method works.
 +
  
 ====== Sources ====== ====== Sources ======
 # Software used in this guide: \\ # Software used in this guide: \\
 [[http://slackware.uk/slackwarearm/slackwarearm-current/]]  # Slackware ARM -current OS. \\ [[http://slackware.uk/slackwarearm/slackwarearm-current/]]  # Slackware ARM -current OS. \\
-[[https://nginx.org/download/]] # Nginx 1.17.web server software [gzip tarball]. \\+[[https://nginx.org/download/]] # Nginx 1.17.web server software [gzip tarball]. \\
 [[https://slackbuilds.org/slackbuilds/14.2/network/nginx/]] # SlackBuilds.org nginx package build script files. \\ [[https://slackbuilds.org/slackbuilds/14.2/network/nginx/]] # SlackBuilds.org nginx package build script files. \\
 [[https://slackbuilds.org/repository/14.2/system/goaccess/]] # SlackBuilds.org goaccess package build script files. \\ [[https://slackbuilds.org/repository/14.2/system/goaccess/]] # SlackBuilds.org goaccess package build script files. \\
 howtos:hardware:arm:nginx ()