Code Monkey home page Code Monkey logo

nginx-init-ubuntu's Introduction

nginx-init-ubuntu

Status

Build Status

Current release: v3.9.0

Previous stable release v3.8.0

Notes: v3.8.0 has been stable for the last several months without issues. v3.9.0 while stable, is new.

Info

Tried and true Nginx init script.

Ubuntu, Vagrant, and Docker tested!

You may also want to use the AnsibleShipyard ansible-nginx playbook.

Simple ansible playbook sits in this repository.

Author: Jason Giedymin <jasong -at- apache -=dot=- org>

Check out my other repos!

Support

Rest assured that this repo will be maintained indefinitely beyond Ubuntu LTS and systemd adoption into Ubuntu stable.

Last tested with:

  1. Ubuntu 14.xx (works with prior versions)
  2. nginx-1.7.9 (works with prior versions)

Notes

It is recommended to install Nginx by doing a full compile & build. Not all package repositories keep their branches updated. For security it is your duty to maintain a good working environment and thus includes all interfacing applications. This script works turn-key with the default compile of nginx. It is fully recommended that you go through the variables contained within this script if you have a custom compiled build.

A great resource is the Nginx Wiki.

Basic Install

Basic install instructions, use sudo if necessary for the below (depends on your setup/security).

# [optional as you may have these installed]
sudo apt-get install libpcre3-dev zlib1g-dev

mkdir -p ~/temp/nginx-install
cd ~/temp/nginx-install

# download/curl/wget nginx 
wget http://nginx.org/download/nginx-1.7.9.tar.gz
tar -xvf nginx-1.7.9.tar.gz
cd nginx-1.7.9/
./configure
make
sudo make install

#copy/download/curl/wget the init script
sudo wget https://raw.githubusercontent.com/JasonGiedymin/nginx-init-ubuntu/master/nginx -O /etc/init.d/nginx
sudo chmod +x /etc/init.d/nginx

service nginx status  # to poll for current status
service nginx stop    # to stop any servers if any
service nginx start   # to start the server

#[optional] 
sudo update-rc.d -f nginx defaults

#[optional remove the upstart script]
sudo update-rc.d -f nginx remove

Advanced Configuration

If you need to override the values within the script you should use /etc/default/nginx.

You can override any of these values:

Variable Function
PATH Path environment variable
NGINXPATH Root path where installed
DAEMON Path to Deamon binary
PS Process name
PIDNAME Lets you do $PS-slave
PIDFILE Pid file
PIDSPATH Default PID location
DESCRIPTION Process description
RUNAS User to run as
NGINX_CONF_FILE Config file path

For instance, if you needed to change the description of the server during logging:

# Edit [/etc/default/nginx] and add the below line
DESCRIPTION="My Awesome Nginx Server..."

# Next run the below command:
sudo service nginx restart

# Output of running restart with nginx defaults file:
* Stopping My Super Nginx Server...                                  [ OK ] 
* Starting My Super Nginx Server...                                  [ OK ]

# Notice that is says "My Super Nginx Server..." as opposed to the default
# "Nginx Server...".

The NGINXPATH value should point to your installation of Nginx, the default is /usr/local/nginx

It's likely you'll need to update the NGINXPATH value if you didn't install from source. Eg, if you install Nginx using apt-get on Ubuntu nginx will be installed to /etc/nginx

# Changing NGINXPATH when Nginx was installed with apt-get
NGINXPATH=/etc/nginx

Testing

Tests run as part of the deployment scripts integration-tests.yml.

To start make sure you have vagrant, and ansible installed.

Download the Ubuntu base box:

vagrant box add ubuntu-14.10 https://cloud-images.ubuntu.com/vagrant/utopic/current/utopic-server-cloudimg-amd64-vagrant-disk1.box

Run vagrant:

vagrant up

Manually provision again:

vagrant provision

Using with Docker

A basic Dockerfile will arrive shortly for testing, but note that I focued my efforts on creating an nginx ansible role. This repo has a Dockerfile which will install Nginx along with nginx-init-ubuntu (this repo) using ansible. Until the basic testing Dockerfile is in place here please refer to the ansible role and it's Dockerfile -- if your looking for stability.

If your looking for a more production and developer friendly Dockerfile, look here.

When using the ansible role mentioned above you will need to set nginx_docker_override to True as the role will detect if running within a Dockerfile. This is to prevent nginx running in daemon mode.

A copy of nginx-init-ubuntu is present in the ansible role.

Contributions

Contributions are welcome!

nginx-init-ubuntu's People

Contributors

actuallymentor avatar jasongiedymin avatar lauritzsh avatar mattbearman avatar nvartolomei avatar sturgill avatar violuke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nginx-init-ubuntu's Issues

better configuration instructions

If you look at the forks of this script, the main change people make is to the default values of a few variables. It seems like people are missing instructions on how to configure these using /etc/default/nginx [1].

I suggest adding instructions to clearly show how to customize all variables that people typically need customized.

[1] -

# Include nginx defaults if available

Script for Ubuntu 16.04 systemd

This is for Ubuntu 14.04 upstart script. Do you have any plan to update it for Ubuntu 16.04 to use systemd script.

Thanks.
Andrew

The settings in `/etc/default/nginx` is not updated to const defined earlier

As per title, I would suggest this

#
# ...
#

#------------------------------------------------------------------------------
#                               Functions
#------------------------------------------------------------------------------
LSB_FUNC=/lib/lsb/init-functions

# Test that init functions exists
test -r $LSB_FUNC || {
    echo "$0: Cannot find $LSB_FUNC! Script exiting." 1>&2
    exit 5
}

. $LSB_FUNC

#------------------------------------------------------------------------------
#                               Consts
#------------------------------------------------------------------------------
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
PS="nginx"
PIDNAME="nginx"                #lets you do $PS-slave
PIDFILE=$PIDNAME.pid     #pid file
RUNAS=root                        #user to run as
SCRIPT_OK=0                     #ala error codes
SCRIPT_ERROR=1             #ala error codes
TRUE=1                               #boolean
FALSE=0                             #boolean

#------------------------------------------------------------------------------
#                               Simple Tests
#------------------------------------------------------------------------------
# Include nginx defaults if available
if [ -f /etc/default/nginx ]; then
    . /etc/default/nginx
fi

DESCRIPTION=${DESCRIPTION:-"Nginx Server..."}
NGINXPATH=${NGINXPATH:-/usr/local/nginx}
DAEMON=${NGINXPATH}/sbin/nginx
PIDSPATH=${NGINXPATH}/logs      #default pid location, you should change it
NGINX_CONF_FILE=${NGINXPATH}/conf/nginx.conf

lockfile=/var/lock/subsys/nginx

#
# ...
#

Get 502 on all sites after reload

After running reload all sites display a 502 error and restarting the service does not work either. I have to kill all the nginx workers and run start again to get nginx back up and running.

Any idea what may be causing this?

Variable description in your README.md

Great work, love it :)

The default values though are not self explanatory:

PATH
NGINXPATH
DAEMON
PS
PIDNAME
PIDFILE
PIDSPATH
DESCRIPTION
RUNAS
NGINX_CONF_FILE

I have no idea what the differences and connections are between PATH and NGINXPATH. Or for example PIDNAME, PIDFILE and PIDSPATH.

Where can I find these?

nginx permissions denied

ubuntu 14.04 followed the instructions to a tee. checked the permissions with ls -l, I've chmod already exactly as the instructions tell. Still no permission for nginx

Unable to stop nginx

I've resolved a couple of issues with this init script by overriding variables in /etc/default/nginx, and the Nginx server now starts correctly, but I am unable to stop the nginx process via the service command. Can you think of a variable that might interfere with stopping the process, but not with starting it?

problem with "service nginx restart"

ubuntu server 12.04.03 x86_64

nginx-1.5.6.tar.gz

                Putty Print

root@ubuntu:/etc/init.d# service nginx status

  • nginx found running with processes: 1368 1366
    root@ubuntu:/etc/init.d# service nginx reload
    nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
    nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
  • Reloading (via HUP) Nginx Server... Hangup
    root@ubuntu:/etc/init.d# service nginx restart
  • Stopping Nginx Server... [ OK ]
    root@ubuntu:/etc/init.d# service nginx status
  • nginx is NOT running.
    root@ubuntu:/etc/init.d#

Version Command

Not an issue but a suggestion for enabling Version command to output the list of compiled installed Nginx modules.

/etc/init.d/nginx: 1: /etc/init.d/nginx: N: not found

I got this error message every time when I start a new nginx server and I don't know is it a problem or it's okay:

root@1abf1c2ef16c:/bin# sudo service nginx start
/etc/init.d/nginx: 1: /etc/init.d/nginx: N: not found

  • Starting Nginx Server... [ OK ]

root@1abf1c2ef16c:/bin#

I needed to modify the DAEMON value, because I installed the nginx binary in different place:

DAEMON=${DAEMON:-/usr/local/sbin/nginx} # path to daemon binary

And this is my report when I built Nginx from source:

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/local/nginx"
    nginx binary file: "/usr/local/sbin"
    nginx configuration prefix: "/usr/local/nginx/conf"
    nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
    nginx pid file: "/usr/local/nginx/logs/nginx.pid"
    nginx error log file: "/usr/local/nginx/logs/error.log"
    nginx http access log file: "/usr/local/nginx/logs/access.log"
    nginx http client request body temporary files: "client_body_temp"
    nginx http proxy temporary files: "proxy_temp"
    nginx http fastcgi temporary files: "fastcgi_temp"
    nginx http uwsgi temporary files: "uwsgi_temp"
    nginx http scgi temporary files: "scgi_temp"

Request to add umask

Thank you for the script -- it's great. I had to make one change that might help you and your users... I added a umask 007 to the script. This is because nginx creates log files where anyone can read them. This changes things, so only owner and group members can read them.

Ubuntu 20.04 - service nginx "reload" error

Hi - been using the script for many years. However, in Ubuntu 20.04:

sudo service nginx reload
Job for nginx.service failed.
See "systemctl status nginx.service" and "journalctl -xe" for details.

sudo service nginx status
● nginx.service - LSB: nginx init.d dash script for Ubuntu or other *nix.
Loaded: loaded (/etc/init.d/nginx; generated)
Active: active (running) since Sun 2020-12-13 22:40:39 UTC; 29min ago
Docs: man:systemd-sysv-generator(8)
Process: 11201 ExecStart=/etc/init.d/nginx start (code=exited, status=0/SUCCESS)
Process: 11736 ExecReload=/etc/init.d/nginx reload (code=exited, status=7)
Main PID: 11217 (nginx)
Tasks: 3 (limit: 1137)
Memory: 6.9M
CGroup: /system.slice/nginx.service
├─11217 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
├─11218 nginx: worker process
└─11219 nginx: cache manager process

Dec 13 22:40:38 abc nginx[11201]: ...done.
Dec 13 22:40:38 abc systemd[1]: nginx.service: Can't open PID file /usr/local/nginx/logs/nginx.pid (yet?) after start: Operation not permitted
Dec 13 22:40:39 abc systemd[1]: Started LSB: nginx init.d dash script for Ubuntu or other *nix..
Dec 13 23:10:22 abc systemd[1]: Reloading LSB: nginx init.d dash script for Ubuntu or other *nix..
Dec 13 23:10:22 abc nginx[11740]: nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
Dec 13 23:10:22 abc nginx[11740]: nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
Dec 13 23:10:22 abc nginx[11736]: * Reloading (via HUP) Nginx Server...
Dec 13 23:10:22 abc nginx[11736]: ...fail!
Dec 13 23:10:22 abc systemd[1]: nginx.service: Control process exited, code=exited, status=7/NOTRUNNING

Will be very helpful if you could update the script to support "reload" on Ubuntu 20.04.
BTW, no issue with "restart".
Thank you.

/etc/init.d/nginx: You don't have permissions to execute nginx.

I'm using Nginx 1.5.10 on Ubuntu 13.10 and I have compiled Nginx with the following options in my Ansible playbook:

downloads: /home/user/downloads

  • name: run configure nginx with naxsi
    command: ./configure --add-module={{ downloads }}/naxsi/naxsi_src/ --prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --user={{ nginx_user }} --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --without-mail_pop3_module --without-mail_smtp_module --without-mail_imap_module --without-http_uwsgi_module --without-http_scgi_module chdir={{ downloads }}nginx/

After uploading your init script to /etc/init.d/nginx and making sure the permissions are 755 with root/root I still don't have permissions to execute nginx.

  • name: upload nginx init script
    copy: src=./roles/nginx/files/nginx.sh
    dest=/etc/init.d/nginx
    owner=root
    group=root
    mode=0755

I tried to solve it changing a few variables in your script:

PIDSPATH=/var/run instead of /usr/local/nginx/logs
NGINX_CONF_FILE="/etc/nginx/nginx.conf" instead of "/usr/local/nginx/conf/nginx.conf"

But still the same problem. Any ideas?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.