Skip to content

Instantly share code, notes, and snippets.

@mimosz
Created December 25, 2012 09:00
Show Gist options
  • Save mimosz/4372383 to your computer and use it in GitHub Desktop.
Save mimosz/4372383 to your computer and use it in GitHub Desktop.
Ubuntu 下配置文件。
#! /bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $syslog $remote_fs
# Required-Stop: $syslog $remote_fs
# Should-Start: $local_fs
# Should-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: nginx - Persistent key-value db
# Description: nginx - Persistent key-value db
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/nginx
NAME=nginx
PIDFILE=/var/run/$NAME.pid
test -x $DAEMON || exit 0
if [ -f /etc/default/nginx ] ; then
. /etc/default/nginx
fi
set -e
. /lib/lsb/init-functions
test_nginx_config() {
if $DAEMON -t $DAEMON_OPTS >/dev/null 2>&1
then
return 0
else
$DAEMON -t $DAEMON_OPTS
return $?
fi
}
start() {
test_nginx_config
start-stop-daemon --start --quiet --pidfile $PIDFILE \
--exec $DAEMON -- $DAEMON_OPTS || true
}
stop() {
start-stop-daemon --stop --quiet --pidfile $PIDFILE \
--exec $DAEMON || true
}
reload() {
test_nginx_config
start-stop-daemon --stop --signal HUP --quiet --pidfile $PIDFILE \
--exec $DAEMON || true
}
case "$1" in
start)
echo -n "Starting $DESC: "
start
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
stop
echo "$NAME."
;;
restart|force-reload)
echo -n "Restarting $DESC: "
stop
sleep 1
start
echo "$NAME."
;;
reload)
echo -n "Reloading $DESC configuration: "
reload
echo "$NAME."
;;
configtest)
echo -n "Testing $DESC configuration: "
if test_nginx_config
then
echo "$NAME."
else
exit $?
fi
;;
status)
status_of_proc -p $PIDFILE "$DAEMON" nginx && exit 0 || exit $?
;;
*)
echo "Usage: $NAME {start|stop|restart|reload|force-reload|status|configtest}" >&2
exit 1
;;
esac
exit 0
# /etc/nginx/conf/nginx.conf
dso {
load ngx_http_access_module.so;
load ngx_http_autoindex_module.so;
load ngx_http_upstream_ip_hash_module.so;
load ngx_http_upstream_least_conn_module.so;
}
worker_processes auto;
worker_cpu_affinity auto;
error_log /var/logs/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/logs/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root /etc/nginx/html;
index index.html index.htm;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /etc/nginx/html/50x.html;
location = /50x.html {
root /etc/nginx/html;
}
}
## Load virtual host conf files. ##
include /etc/nginx/conf/sites-enabled/*;
}
## Load another configs from conf.d/ ##
include /etc/nginx/conf/conf.d/*.conf;
# /etc/nginx/conf/sites-enabled/meta
upstream meta_cluster {
server 127.0.0.1:9292;
}
server {
listen 80;
# 修改成自己的域名
server_name db.innshone.com 42.96.138.76;
# 修改成自己的应用目录,不知道的,使用 pwd 命令查看。
root /home/howl/meta/public/;
location ~ ^/(img|images|javascripts|stylesheets)/.* {
expires max;
add_header Cache-Control public;
access_log off;
}
try_files $uri $uri/index.html $uri.html @meta_cluster;
location @meta_cluster {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_max_temp_file_size 0;
proxy_pass http://meta_cluster;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment