美文网首页
nginx 安装配置 和 二级域名设置

nginx 安装配置 和 二级域名设置

作者: 踩踩踩踩坑 | 来源:发表于2015-11-27 13:57 被阅读423次

参考

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(第一次需要)

相关文章

  • NGINX安装

    一、NGINX安装 下载: 解压: 安装依赖: 配置: 安装: 二、配置开机启动 创建nginx服务文件: 设置执...

  • centos

    创建nginx服务 安装nginx 设置开启启动 配置nginx.config打开 Nginx 的默认配置文件 /...

  • nginx 安装配置 和 二级域名设置

    参考 http://www.rubytreesoftware.com/resources/ruby-on-rail...

  • CentOS 安装Nginx

    一、安装基础环境 二、安装Nginx 下载安装包 配置 编译安装 常用Nginx命令 设置开机自启动

  • Nginx:通过DNS与Nginx代理,实现本地的生产与开发接口

    一、安装 1)添加源 2)安装Nginx 3)启动Nginx并设置开机自动运行 二、配置及使用 1.配置域名映射 ...

  • nginx centerOs

    安装 配置文件位置 设置 启动、停止nginx 测试nginx配置是否正确 先停止再启动(推荐): 重新加载配置文...

  • Centos7编译安装nginx

    下载nginx 解压 安装依赖 前往解压目录 配置设置(使用默认配置) 编译安装 前往安装目录 启动 查看进程 ...

  • 从零开始使用nginx-rtmp-module搭建RTMP普通推

    整体步骤如下:1. 安装nginx-rtmp-module。2. 修改nginx配置,普通推拉流设置和权限验证推拉...

  • Linux-centos7安装nginx

    按下面步骤即可安装: 1.更新安装源 2.安装nginx 3.重启nginx 4.设置开机启动 配置nginx 1...

  • 二级域名配置步骤

    转自二级域名配置步骤。 这篇文章主要介绍在配置二级域名时候的步骤,主要涉及到nginx、dns的配置,有相同需求的...

网友评论

      本文标题:nginx 安装配置 和 二级域名设置

      本文链接:https://www.haomeiwen.com/subject/xkpdhttx.html