亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

centos6.5服務(wù)器安裝Nginx設(shè)置服務(wù)和開(kāi)機(jī)自啟的方法

 更新時(shí)間:2017年08月07日 14:55:03   作者:Clone丶記憶  
本篇文章主要介紹了centos6.5服務(wù)器安裝Nginx設(shè)置服務(wù)和開(kāi)機(jī)自啟的方法,具有一定的參考價(jià)值,有興趣的小伙伴可以了解一下

本文介紹了centos6.5服務(wù)器安裝Nginx設(shè)置服務(wù)和開(kāi)機(jī)自啟的方法,分享給大家,也給自己留個(gè)筆記

1、安裝Nginx及其依賴

首先是老套路,使用ssh鏈接服務(wù)器,還記得以前的代碼嗎?

ssh -t 用戶名@服務(wù)器IP或者域名 -p 22
<!--用戶名一般是root,方便操作,我的登錄代碼如下-->
ssh -t root@acheng1314.cn -p 22

在終端中輸入上面命令按下回車(chē),要求我們輸入密碼,這個(gè)密碼是不可見(jiàn)的,所以一定要輸入正確。

鏈接到服務(wù)器后,我們切換到常用的安裝路徑,當(dāng)然我服務(wù)器上面的安裝路徑是/usr/src,接著開(kāi)始在終端操作:

<!--切換到安裝目錄下-->
cd /usr/src
<!--創(chuàng)建Nginx文件夾用來(lái)存放Nginx相關(guān)的資源和依賴-->
mkdir Nginx
<!--下載資源和依賴-->
yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel 
<!--上面的命令一般來(lái)說(shuō)會(huì)是不需要安裝什么,不過(guò)這都不重要,我們接著會(huì)重新安裝指定的版本-->

<!--下載pcre-->
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz
<!--解壓-->
tar -zxvf pcre-8.40.tar.gz
<!--切換到pcre目錄-->
cd pcre-8.40
<!--設(shè)置-->
./configure
<!--編譯-->
make
<!--安裝-->
make install

<!--切換到Nginx主目錄-->
cd ..
<!--下載及安裝zlib-->
wget http://zlib.net/zlib-1.2.11.tar.gz
<!--解壓-->
tar -zxvf zlib-1.2.11.tar.gz
<!--切換到zlib目錄-->
cd zlib-1.2.11
<!--設(shè)置、編譯、安裝-->
./configure
make
make install


<!--切換到Nginx主目錄-->
cd ..
<!--下載及準(zhǔn)備ssl-->
wget http://www.openssl.org/source/openssl-fips-2.0.14.tar.gz
<!--解壓-->
tar -zxvf openssl-fips-2.0.14.tar.gz
<!--yum安裝ssl-->
yum -y install openssl openssl-devel

<!--下載及安裝nginx-->
wget http://nginx.org/download/nginx-1.4.2.tar.gz
tar -zxvf nginx-1.4.2.tar.gz
cd nginx-1.4.2
<!--設(shè)置Nginx安裝目錄/opt/nginx,且添加ssl支持-->
./configure --prefix=/opt/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre
make
make install

到這里來(lái)講,我們的nginx安裝完成了,但是我們還需要做更多的事情,那就是配置服務(wù)器,添加ssl訪問(wèn),設(shè)置服務(wù)和開(kāi)機(jī)啟動(dòng)

2、配置服務(wù)器

互聯(lián)網(wǎng)上關(guān)于服務(wù)器設(shè)置的很多,但是準(zhǔn)確闡述的卻不是那么多,而我剛好是在看了他們的東西后就呵呵了。正確的配置方法如下:

<!--切換到nginx設(shè)置目錄-->
cd /opt/nginx/conf
<!--vim編輯nginx配置文件-->
vi nginx.conf

我的nginx.conf如下:

#user nobody;
worker_processes 1;

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid    logs/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 logs/access.log main;

  sendfile    on;
  #tcp_nopush   on;

  #keepalive_timeout 0;
  keepalive_timeout 65;

  #gzip on;
# 注意這里是設(shè)置本機(jī)的相關(guān)的東西,建議不要更改
  server {
    listen    80;
    server_name localhost;

    #charset koi8-r;

    #access_log logs/host.access.log main;

    location / {
    root  html;
        index index.html index.htm;
    # proxy_pass http://localhost; 
    # proxy_set_header  Host  $host;
    # proxy_set_header  X-Real-IP  $remote_addr;
    # proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    #error_page 404       /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page  500 502 503 504 /50x.html;
    location = /50x.html {
      root  html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #  proxy_pass  http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #  root      html;
    #  fastcgi_pass  127.0.0.1:9000;
    #  fastcgi_index index.php;
    #  fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
    #  include    fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #  deny all;
    #}
  }


  # another virtual host using mix of IP-, name-, and port-based configuration
  #
  #server {
  #  listen    8000;
  #  listen    somename:8080;
  #  server_name somename alias another.alias;

  #  location / {
  #    root  html;
  #    index index.html index.htm;
  #  }
  #}

# 這里是設(shè)置本機(jī)的https訪問(wèn)的,這里必須設(shè)置才能正確時(shí)https
  # HTTPS server
  #
  server {
    listen    443;
    server_name localhost acheng1314.cn www.acheng1314.cn;

    ssl         on;
    # 這里是你申請(qǐng)的簽名,扔到conf下面的cert目錄中
    ssl_certificate   cert/214217283570796.pem;
    ssl_certificate_key cert/214217283570796.key;

    ssl_session_timeout 5m;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_prefer_server_ciphers  on;

    location / {
    #  root  html;
    #  index index.html index.htm;
  proxy_pass http://localhost;
  proxy_set_header  Host  $host;
  proxy_set_header  X-Real-IP  $remote_addr;
  proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}
# 這里是設(shè)置域名跳轉(zhuǎn)的,轉(zhuǎn)發(fā)這些域名到本機(jī)的8080端口,
server { 
  listen    80; 
  server_name *.acheng1314.cn acheng1314.cn; 
  location / { 
    proxy_pass http://localhost:8080/; 
    proxy_set_header  Host  $host; 
    proxy_set_header  X-Real-IP  $remote_addr; 
    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for; 
  } 
}   

}

其實(shí)在寫(xiě)這個(gè)的時(shí)候必須注意的是,不管什么應(yīng)用程序端口不能沖突!比如說(shuō)我的nginx是綁定的80端口,如果tomcat再設(shè)定80端口,那么我的設(shè)置就算是綁定到localhost去也是會(huì)轉(zhuǎn)發(fā)失敗的!畢竟網(wǎng)絡(luò)端口只能一個(gè)應(yīng)用程序占用。

<!--檢查我們的設(shè)置是否正確,正確或者錯(cuò)誤都有對(duì)應(yīng)的提示-->
/opt/nginx/sbin/nginx -t
<!--配置正確,則啟用nginx-->
/opt/nginx/sbin/nginx
<!--重新載入配置文件-->
/opt/nginx/sbin/nginx -t

<!--當(dāng)然到了這里的時(shí)候肯定還不能通行,畢竟我們防火墻還把443端口攔截的,所以接著走起來(lái)。-->
<!--添加443端口到防火墻-->
/sbin/iptables -I INPUT -p tcp --dport 443 -j ACCEPT
<!--保存防火墻配置-->
/etc/rc.d/init.d/iptables save
<!--是配置文件生效-->
/etc/init.d/iptables status

走到這一步,我們可以測(cè)試一下服務(wù)器了,按照正常的來(lái)講,我現(xiàn)在的服務(wù)器已經(jīng)是http和https都已經(jīng)完全支持了。

3、設(shè)置服務(wù)和自啟

其實(shí)說(shuō)來(lái),這里基本也沒(méi)啥注意的,只要nginx路徑設(shè)置正確即可。

#!/bin/sh
# Name:nginx4comex
# nginx - this script starts and stops the nginx daemon
#
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
#        proxy and IMAP/POP3 proxy server
# processname: nginx
# config:   /opt/nginx/conf/nginx.conf
# pidfile:   /comexHome/nginx/nginx.pid
#
# Created By http://comexchan.cnblogs.com/

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0

NGINX_DAEMON_PATH="/opt/nginx/sbin/nginx"
NGINX_CONF_FILE="/opt/nginx/conf/nginx.conf"
NGINX_LOCK_FILE="/var/lock/subsys/nginx4comex"
prog=$(basename $NGINX_DAEMON_PATH)

start() {
  [ -x $NGINX_DAEMON_PATH ] || exit 5
  [ -f $NGINX_CONF_FILE ] || exit 6
  echo -n $"Starting $prog: "
  daemon $NGINX_DAEMON_PATH -c $NGINX_CONF_FILE
  retval=$?
  echo
  [ $retval -eq 0 ] && touch $NGINX_LOCK_FILE
  return $retval
}

stop() {
  echo -n $"Stopping $prog: "
  killproc $prog -QUIT
  retval=$?
  echo
  [ $retval -eq 0 ] && rm -f $NGINX_LOCK_FILE
  return $retval
}

restart() {
  configtest || return $?
  stop
  start
}

reload() {
  configtest || return $?
  echo -n $"Reloading $prog: "
  killproc $NGINX_DAEMON_PATH -HUP
  RETVAL=$?
  echo
}

force_reload() {
  restart
}

configtest() {
 $NGINX_DAEMON_PATH -t -c $NGINX_CONF_FILE
}

rh_status() {
  status $prog
}

rh_status_q() {
  rh_status >/dev/null 2>&1
}

case "$1" in
  start)
    rh_status_q && exit 0
    $1
    ;;
  stop)
    rh_status_q || exit 0
    $1
    ;;
  restart|configtest)
    $1
    ;;
  reload)
    rh_status_q || exit 7
    $1
    ;;
  force-reload)
    force_reload
    ;;
  status)
    rh_status
    ;;
  condrestart|try-restart)
    rh_status_q || exit 0
      ;;
  *)
    echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
    exit 2
esac

上面的代碼就是用來(lái)創(chuàng)建服務(wù)的代碼,將他們保存在nginx4comex文件中(這個(gè)文件我仍在了/opt/nginx目錄下,一樣使用vim編寫(xiě))。注意下面的代碼和你的配置對(duì)應(yīng)即可。

NGINX_DAEMON_PATH="/opt/nginx/sbin/nginx"
NGINX_CONF_FILE="/opt/nginx/conf/nginx.conf"

接著我們繼續(xù)終端指令操作。

<!--授權(quán)nginx4comex可執(zhí)行-->
chmod u+x nginx4comex
<!--拷貝nginx4comex到/etc/init.d目錄-->
cp nginx4comex /etc/init.d
<!--檢查運(yùn)行狀態(tài)-->
service nginx4comex status
<!--添加到啟動(dòng),先vim打開(kāi)啟動(dòng)文件,然后添加啟動(dòng)代碼-->
vim /etc/rc.local
<!--添加的啟動(dòng)代碼如下-->
/etc/init.d/nginx4comex start

<!--至此我們的啟動(dòng)也添加完成,現(xiàn)在重啟檢查效果-->
reboot

最后來(lái)說(shuō)我們已經(jīng)設(shè)置了nginx代理tomcat,還設(shè)置了對(duì)應(yīng)的服務(wù)器程序自啟動(dòng)。

注意!nginx4comex是不能被chkconfig的,具體原因我也不清楚,但是原作者的文章中確實(shí)用了chkconfig的方法加入了啟動(dòng),對(duì)linux有興趣的可以去試一試。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Linux 文件和目錄權(quán)限詳細(xì)介紹

    Linux 文件和目錄權(quán)限詳細(xì)介紹

    這篇文章主要介紹了Linux 文件和目錄權(quán)限詳細(xì)介紹的相關(guān)資料,需要的朋友可以參考下
    2016-10-10
  • Linux平臺(tái)安裝redis及redis擴(kuò)展的方法

    Linux平臺(tái)安裝redis及redis擴(kuò)展的方法

    這篇文章主要介紹了Linux平臺(tái)安裝redis及redis擴(kuò)展的方法,較為詳細(xì)的分析了Linux平臺(tái)redis安裝步驟、操作命令與相關(guān)注意事項(xiàng),需要的朋友可以參考下
    2018-08-08
  • 101個(gè)腳本之建立linux回收站的腳本

    101個(gè)腳本之建立linux回收站的腳本

    眾所周知,linux是沒(méi)有回收站的,一些人很害怕刪錯(cuò)東西(有經(jīng)驗(yàn)的linux管理員極少范這錯(cuò)誤),個(gè)人不建議回收站,而應(yīng)該是培養(yǎng)個(gè)人的安全意識(shí)。有點(diǎn)小跑題
    2016-08-08
  • CentOS7開(kāi)啟MySQL8主從備份、每日定時(shí)全量備份(推薦)

    CentOS7開(kāi)啟MySQL8主從備份、每日定時(shí)全量備份(推薦)

    這篇文章主要介紹了CentOS7開(kāi)啟MySQL8主從備份、每日定時(shí)全量備份,解決了鏈接mysql數(shù)據(jù)庫(kù)很慢的問(wèn)題,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-11-11
  • Windows 10 太難用如何定制你的 Ubuntu方法詳解

    Windows 10 太難用如何定制你的 Ubuntu方法詳解

    這篇文章主要介紹了Windows 10 太難用,如何定制你的 Ubuntu,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-08-08
  • 解決Vmware虛擬機(jī)安裝centos8報(bào)錯(cuò)“Section?%Packages?Does?Not?End?With?%End.?Pane?Is?Dead”

    解決Vmware虛擬機(jī)安裝centos8報(bào)錯(cuò)“Section?%Packages?Does?Not?End?W

    這篇文章介紹了解決Vmware虛擬機(jī)安裝centos8報(bào)錯(cuò)“Section?%Packages?Does?Not?End?With?%End.?Pane?Is?Dead”的方法,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2022-05-05
  • linux下獲取當(dāng)前時(shí)間的相關(guān)函數(shù)

    linux下獲取當(dāng)前時(shí)間的相關(guān)函數(shù)

    這篇文章主要介紹了linux下獲取當(dāng)前時(shí)間的相關(guān)函數(shù),具有很好的參考價(jià)值,希望對(duì)大家有所幫助,
    2023-09-09
  • Linux深入理解進(jìn)程和文件及內(nèi)存管理問(wèn)題

    Linux深入理解進(jìn)程和文件及內(nèi)存管理問(wèn)題

    這篇文章主要介紹了Linux深入理解進(jìn)程和文件及內(nèi)存管理問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2025-03-03
  • Linux文件重定向的高級(jí)技巧與實(shí)踐

    Linux文件重定向的高級(jí)技巧與實(shí)踐

    在Linux中,文件重定向是指將命令的輸入和輸出重定向到文件或其他設(shè)備,而不是默認(rèn)的標(biāo)準(zhǔn)輸入(stdin)和標(biāo)準(zhǔn)輸出(stdout),它是通過(guò)不同的符號(hào)來(lái)實(shí)現(xiàn)的,本文給大家介紹了Linux文件重定向的高級(jí)技巧與實(shí)踐,需要的朋友可以參考下
    2025-07-07
  • Linux下安裝Python3.6及避坑指南

    Linux下安裝Python3.6及避坑指南

    這篇文章主要介紹了Linux下Python3.6的安裝及避坑指南,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-05-05

最新評(píng)論