nginx 安裝配置 和 二級域名設置

參考

http://www.rubytreesoftware.com/resources/ruby-on-rails-41-ubuntu-1404-server-configuration

https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-virtual-hosts-on-ubuntu-14-04-lts

sudo apt-get update

sudo apt-get install nginx


安裝RVM

# sudo apt-get install curl

# curl -L https://get.rvm.io | bash -s stable

# source ~/.rvm/scripts/rvm



重啟

sudo service nginx restart

查看 nginx log

/var/log/nginx? access.log? error.log

查看配置文件

nginx -t

1. /etc/nginx/sites-available

upstream unicorn_learn_ground {

server unix:/www/learn_ground/shared/sockets/unicorn.sock fail_timeout=0;

}

server {

listen 80 default_server;

listen [::]:80 default_server ipv6only=on;

server_name server;

root /www/learn_ground/public;

location ~ ^/assets/ {

gzip_static on;

expires max;

add_header Cache-Control public;

}

try_files $uri/index.html $uri @unicorn;

location @unicorn {

proxy_set_header Host $http_host;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_redirect off;

proxy_pass http://unicorn_learn_ground;

}

error_page 500 502 503 504 /500.html;

client_max_body_size 4G;

keepalive_timeout 10;

}

2. sudo ln -s /etc/nginx/sites-available/learn_ground /etc/nginx/sites-enabled/

3. sudo nano /etc/init.d/unicorn_learn_ground

#!/bin/sh

### BEGIN INIT INFO

# Provides:? ? ? ? ? unicorn

# Required-Start:? ? $remote_fs $syslog

# Required-Stop:? ? $remote_fs $syslog

# Default-Start:? ? 2 3 4 5

# Default-Stop:? ? ? 0 1 6

# Short-Description: Manage unicorn server

# Description:? ? ? Start, stop, restart unicorn server for a specific application.

### END INIT INFO

set -e

# Feel free to change any of the following variables for your app:

TIMEOUT=${TIMEOUT-60}

APP_ROOT=/www/learn_ground

PID=$APP_ROOT/tmp/pids/unicorn.pid

CMD="cd $APP_ROOT; bundle exec unicorn -D -c $APP_ROOT/config/unicorn.rb -E production"

AS_USER=root

set -u

OLD_PIN="$PID.oldbin"

sig () {

test -s "$PID" && kill -$1 `cat $PID`

}

oldsig () {

test -s $OLD_PIN && kill -$1 `cat $OLD_PIN`

}

run () {

if [ "$(id -un)" = "$AS_USER" ]; then

eval $1

else

su -c "$1" - $AS_USER

fi

}

case "$1" in

start)

sig 0 && echo >&2 "Already running" && exit 0

run "$CMD"

;;

stop)

sig QUIT && exit 0

echo >&2 "Not running"

;;

force-stop)

sig TERM && exit 0

echo >&2 "Not running"

;;

restart|reload)

sig HUP && echo reloaded OK && exit 0

echo >&2 "Couldn't reload, starting '$CMD' instead"

run "$CMD"

;;

upgrade)

if sig USR2 && sleep 2 && sig 0 && oldsig QUIT

then

n=$TIMEOUT

while test -s $OLD_PIN && test $n -ge 0

do

printf '.' && sleep 1 && n=$(( $n - 1 ))

done

echo

if test $n -lt 0 && test -s $OLD_PIN

then

echo >&2 "$OLD_PIN still exists after $TIMEOUT seconds"

exit 1

fi

exit 0

fi

echo >&2 "Couldn't upgrade, starting '$CMD' instead"

run "$CMD"

;;

reopen-logs)

sig USR1

;;

*)

echo >&2 "Usage: $0 "

exit 1

;;

esac

4.sudo chmod755 ?/etc/init.d/unicorn_learn_ground

5.sudo update-rc.d ?unicorn_learn_ground defaults(第一次需要)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容