Cannot Start Nginx Compiled from Source

Posted by Jason Alan Kennedy on Server Fault See other posts from Server Fault or by Jason Alan Kennedy
Published on 2014-08-21T23:05:24Z Indexed on 2014/08/22 16:25 UTC
Read the original article Hit count: 1047

Filed under:
|
|
|

I am trying to compile Nginx from source based on the original compiled Nginx server running on my DigitalOcean server ( Ubuntu-14.04 64x ) but with a few extra modules. I can get everything installed smoothly but I can not get it to start. I am sure the ini is correct because I copied the original source off the current running Nginx server [ Even though I see that Nginx now adds the ini when compiling fron source ].

Below is the [ lengthy process ] that I am performing - add sorry but I wanted to be thorough for those who are in need of the info ]. Because I am a newB to Nginx, I am sure I am missing something or just have it all wrong. If you may look over what I have done and see if you spot anything I need/need to change, I will greatly appreciate it. Thnx!

With the original Nginx server still running:

I check the current/running Nginx configuration so I can build the new Nginx instance the same but with the added modules:

nginx -V
# The out-put:
configure arguments: 
--with-cc-opt='-g -O2 -fstack-protector 
--param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2' 
--with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro' 
--prefix=/usr/share/nginx 
--conf-path=/etc/nginx/nginx.conf 
--http-log-path=/var/log/nginx/access.log 
--error-log-path=/var/log/nginx/error.log 
--lock-path=/var/lock/nginx.lock 
--pid-path=/run/nginx.pid 
--http-client-body-temp-path=/var/lib/nginx/body 
--http-fastcgi-temp-path=/var/lib/nginx/fastcgi 
--http-proxy-temp-path=/var/lib/nginx/proxy 
--http-scgi-temp-path=/var/lib/nginx/scgi 
--http-uwsgi-temp-path=/var/lib/nginx/uwsgi 
--with-debug 
--with-pcre-jit 
--with-ipv6 
--with-http_ssl_module 
--with-http_stub_status_module 
--with-http_realip_module 
--with-http_addition_module 
--with-http_dav_module 
--with-http_geoip_module 
--with-http_gzip_static_module 
--with-http_image_filter_module 
--with-http_spdy_module 
--with-http_sub_module 
--with-http_xslt_module

NOTE: The configure arguments below return errors during 'make' so I removed them. I don't know what they are - could this be related to my issue???

--with-cc-opt='-g -O2 -fstack-protector 
--param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2' 
--with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro'

Moving on:

# So I don't have to sudo every line:
sudo bash

# Check for updates first thing:
apt-get update

# Install various prerequisites needed to compile Nginx:
apt-get install build-essential libgd2-xpm-dev lsb-base zlib1g-dev libpcre3 libpcre3-dev libbz2-dev libxslt1-dev libxml2 libssl-dev libgeoip-dev tar unzip openssl

# Create System users [ if it doesn't exist - but I see its there on DigitalOceans' Droplets all-ready ]:
adduser --system --no-create-home --disabled-login --disabled-password --group www-data

# Download NGINX
wget http://nginx.org/download/nginx-1.7.4.tar.gz
tar -xvzf nginx-1.7.4.tar.gz

# Then Google PageSpeed:
wget https://github.com/pagespeed/ngx_pagespeed/archive/release-1.8.31.4-beta.zip
unzip release-1.8.31.4-beta.zip

# cd into the PageSpeed Directory
cd ngx_pagespeed-release-1.8.31.4-beta/
# and add the PSOL files in there:
wget https://dl.google.com/dl/page-speed/psol/1.8.31.4.tar.gz
tar -xzvf 1.8.31.4.tar.gz

# Get back to the root directory:
cd

# I add the ngx_cache_purge module and will install the Nginx Helper plugin for WP later:
wget https://github.com/FRiCKLE/ngx_cache_purge/archive/2.1.zip
unzip 2.1.zip

# Add the headers-more-nginx-module:
wget https://github.com/openresty/headers-more-nginx-module/archive/v0.25.zip
unzip v0.25.zip

# and the naxsi module for added security:
wget https://github.com/nbs-system/naxsi/archive/0.53-2.tar.gz
tar -xvzf 0.53-2.tar.gz

# cd to the new Nginx directory
cd nginx-1.7.4

# Set up the configuration build based on the current running Nginx config args and add my additional modules:
./configure \
--add-module=$HOME/naxsi-0.53-2/naxsi_src \
--prefix=/usr/share/nginx \
--conf-path=/etc/nginx/nginx.conf \
--http-log-path=/var/log/nginx/access.log \
--error-log-path=/var/log/nginx/error.log \
--lock-path=/var/lock/nginx.lock \
--pid-path=/run/nginx.pid \
--http-client-body-temp-path=/var/lib/nginx/body \
--http-fastcgi-temp-path=/var/lib/nginx/fastcgi \
--http-proxy-temp-path=/var/lib/nginx/proxy \
--http-scgi-temp-path=/var/lib/nginx/scgi \
--http-uwsgi-temp-path=/var/lib/nginx/uwsgi \
--user=www-data \
--group=www-data \
--with-debug \
--with-pcre-jit \
--with-ipv6 \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_dav_module \
--with-http_geoip_module \
--with-http_gzip_static_module \
--with-http_image_filter_module \
--with-http_spdy_module \
--with-http_sub_module \
--with-http_xslt_module \
--with-mail \
--with-mail_ssl_module \
--add-module=$HOME/ngx_pagespeed-release-1.8.31.4-beta \
--add-module=$HOME/ngx_cache_purge-2.1 \
--add-module=$HOME/headers-more-nginx-module-0.25

[ENTER]

Configuration Summary:

Configuration summary
  + using system PCRE library
  + using system OpenSSL library
  + md5: using OpenSSL library
  + sha1: using OpenSSL library
  + using system zlib library

  nginx path prefix: "/usr/share/nginx"
  nginx binary file: "/usr/share/nginx/sbin/nginx"
  nginx configuration prefix: "/etc/nginx"
  nginx configuration file: "/etc/nginx/nginx.conf"
  nginx pid file: "/run/nginx.pid"
  nginx error log file: "/var/log/nginx/error.log"
  nginx http access log file: "/var/log/nginx/access.log"
  nginx http client request body temporary files: "/var/lib/nginx/body"
  nginx http proxy temporary files: "/var/lib/nginx/proxy"
  nginx http fastcgi temporary files: "/var/lib/nginx/fastcgi"
  nginx http uwsgi temporary files: "/var/lib/nginx/uwsgi"
  nginx http scgi temporary files: "/var/lib/nginx/scgi"

Next step:

I cd to root and I check the old Nginx folder locations and double checked the 'make' output to see that they are the same:

whereis nginx
#Output:
nginx: /usr/sbin/nginx /etc/nginx /usr/share/nginx

NOTE: Not sure about the '/usr/sbin/nginx' - Possible issue???

Next I copy the old /etc/nginx/nginx.conf, /etc/nginx/sites-available/default, /etc/nginx/sites-enabled/default, /etc/init.d/nginx to a text file locally for safe keeping to use in the new Nginx server.

Then stop the running Nginx server: service nginx stop , verify it's stopped: service --status-all and the output is: [ - ] nginx

To verify that there are two Nginx directories, I cd to: cd nginx* and the output is an error indicating there are two nginx folders - Cool Beans! :)

Now Install the new Nginx server: cd nginx-1.7.4 make install

# INSTALL OUTPUT ########################################
make -f objs/Makefile install
make[1]: Entering directory `/home/walkingfish/nginx-1.7.4'
test -d '/usr/share/nginx' || mkdir -p '/usr/share/nginx'
test -d '/usr/share/nginx/sbin'                 || mkdir -p '/usr/share/nginx/sbin'
test ! -f '/usr/share/nginx/sbin/nginx'                 || mv '/usr/share/nginx/sbin/nginx'                     '/usr/share/nginx/sbin/nginx.old'
cp objs/nginx '/usr/share/nginx/sbin/nginx'
test -d '/etc/nginx'            || mkdir -p '/etc/nginx'
cp conf/koi-win '/etc/nginx'
cp conf/koi-utf '/etc/nginx'
cp conf/win-utf '/etc/nginx'
test -f '/etc/nginx/mime.types'                 || cp conf/mime.types '/etc/nginx'
cp conf/mime.types '/etc/nginx/mime.types.default'
test -f '/etc/nginx/fastcgi_params'             || cp conf/fastcgi_params '/etc/nginx'
cp conf/fastcgi_params          '/etc/nginx/fastcgi_params.default'
test -f '/etc/nginx/fastcgi.conf'               || cp conf/fastcgi.conf '/etc/nginx'
cp conf/fastcgi.conf '/etc/nginx/fastcgi.conf.default'
test -f '/etc/nginx/uwsgi_params'               || cp conf/uwsgi_params '/etc/nginx'
cp conf/uwsgi_params            '/etc/nginx/uwsgi_params.default'
test -f '/etc/nginx/scgi_params'                || cp conf/scgi_params '/etc/nginx'
cp conf/scgi_params             '/etc/nginx/scgi_params.default'
test -f '/etc/nginx/nginx.conf'                 || cp conf/nginx.conf '/etc/nginx/nginx.conf'
cp conf/nginx.conf '/etc/nginx/nginx.conf.default'
test -d '/run'          || mkdir -p '/run'
test -d '/var/log/nginx' ||             mkdir -p '/var/log/nginx'
test -d '/usr/share/nginx/html'                 || cp -R html '/usr/share/nginx'
test -d '/var/log/nginx' ||             mkdir -p '/var/log/nginx'
#########################################################

I copy/create the files that I saved earlier to txt files in sites-available, the config, default and ini files then symlink them to sites-enabled, and so on.

And now to start the server: service nginx start

And this is where s#!+ hits the fan - Nada. I check to see if Nginx is running with service --status-all and its not. Also with nginx -V and its not installed??? I reboot the system too and still nothing. So I am not sure what is wrong here. The ini was copied over from the old server along with all the other config files after deleting the old files. When I opened the new compiled files, the nginx default data was present so I replaced them with my old original data prior to starting the new server for the first time.

Also to be safe, I rm /etc/nginx/sites-enabled/default and symlinked with ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default with no errors and I verified that the data was in the sites-enabled/default file.

I don't think the server really/fully installed because of the nginx -V result:

The program 'nginx' can be found in the following packages:
 * nginx-core
 * nginx-extras
 * nginx-full
 * nginx-light
 * nginx-naxsi
Try: apt-get install <selected package>

Do/should I apt-get install nginx-1.7.4 ?? Or what package do I use being that its a custom package and make install earlier did nothing??

If you need to see the conf files I copied over from the old to the custom server, LMK and I'll post them.

Again your help here would be appreciated!

© Server Fault or respective owner

Related posts about nginx

Related posts about compile