Got a new laptop recently and hadn't set up php and nginx in a long time went looking for a simple setup and thanks to TechTuts they had just what the doctor ordered.
Saturday, April 15, 2017
Tuesday, September 10, 2013
Nginx - Count of IP addresses in /var/log/nginx/access.log
Inspired by this post which supposedly works for Apache and also works for my Nginx installation. It seems however, some of the comments didn't work quite right on our Debian Lenny equipment.
Did away with grep (instead using cat) and tweaked to fix sorting not working correctly.
cat access.log | cut -d' ' -f1 | sort | uniq -c | sort -rg
If your log is big enough to scroll multiple pages when logged in remotely.
cat access.log | cut -d' ' -f1 | sort | uniq -c | sort -rg | less
Posted by
Joseph
at
6:13 PM
0
comments
Labels: linux, linux command, nginx
Sunday, December 9, 2007
Adding SSL Site To Nginx Quick Start
If now is one of those times you just want to Get 'Er Done and not have a long drawn out process for doing something, welcome.
Step 1: Install OpenSSL
user@machine ~> sudo apt-get install openssl
Step 2: Create Self Signed Certificate [Answer questions in a way that makes you feel good ;)]
user@machine ~> sudo openssl req -new -x509 -days 365 -nodes -out /root/nginx.cert -keyout /root/nginx.key
Step 3: Add SSL options to nginx.conf [/etc/nginx/nginx.conf maybe?]
server {
listen 443;
server_name smallbiztechguy.blogspot.com;
error_page 403 404 500 502 503 504 /nginx-errors/error.htm;
ssl on;
ssl_certificate /root/nginx.cert;
ssl_certificate_key /root/nginx.key;
location / {
charset utf-8;
root /var/www;
index index.htm;
}
}
Step 4: Restart nginx
user@machine ~> ps aux | grep -i nginx
user@machine ~> kill -HUP [id from ps command above]
Posted by
Joseph
at
9:34 PM
0
comments
Monday, October 29, 2007
Test nginx Configuration File
If there is a time when it becomes necessary to test out a nginx.conf file prior to attempting to use it (IOW on a live/production system) here is a handy little command.
user@machine ~> nginx -t -c /etc/nginx/nginx.conf
Posted by
Joseph
at
9:40 PM
2
comments
Labels: linux command, nginx
Tuesday, July 24, 2007
Web Server Restart (nginx) Without Downtime
One of the reasons we've migrated our hosted websites to nginx is not only performance but some notable features that were not, at the time, available for Apache. They may not be available but the longer I work with nginx the less inclined I am to switch back. What happens is that when nginx receives the HUP signal, it tries to parse the configuration file (the specified one, if present, otherwise the default), and if successful, tries to apply a new configuration (i.e. re-open the log files and listen sockets). If successful, nginx runs new worker processes and signals graceful shutdown to old workers. Notified workers close listen sockets but continue to serve current clients. After serving all clients old workers shutdown. If nginx wasn't successful in applying the new configuration, it continues to work with an old configuration.
If you would like to restart nginx without losing incoming connections during the 'restart process' just do the following, taken directly from the English wiki.
Note: I've edited the ps command to be more Linux cross-distro friendly so you might see some child processes as well but you want to issue the kill command against the master process id.user@machine ~> ps aux | grep -i nginx
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 2213 0.0 0.0 6784 2036 ? Ss 03:01 0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
user@machine ~> kill -HUP 2213
Even better:
user@machine ~> kill -HUP `cat /var/run/nginx.pid`
Posted by
Joseph
at
5:20 PM
0
comments
Labels: nginx