CentOS6使用nginx搭建web網(wǎng)站服務(wù)的方法
利用CentOS6搭建簡易的web服務(wù)
提示: 其中沒有涉及到MySQl、MongoDB的安裝和使用,包括docker容器等,使用nginx反向代理靜態(tài)服務(wù)
centOS服務(wù)器
可以選用國外或者國內(nèi)的服務(wù)器,這里只展示centOS系統(tǒng)配置,本人實在window系統(tǒng)下完成下列操作
選購一臺合適的云服務(wù)器,系統(tǒng)為centOS
在window系統(tǒng)下安裝xshell和xftp, 保證可以系統(tǒng)訪問centOS系統(tǒng)
使用xshell連接上云服務(wù)器,使用超級管理員root登錄
登錄完成之后安裝nginx
下面是需要下載的文件:
- 首先安裝
wget # yum install wget - nginx以來與gcc的編譯環(huán)境
# yum install gcc-c++ - nginx的http模塊需要使用pcre來解析正則表達(dá)式
# yum -y install pcre pcre-devel - 依賴的解壓包
# yum -y install zlib zlib-devel - 下載nginx壓縮包
# wget -c https://nginx.org/download/nginx-1.10.3.tar.gz
解壓與安裝:
- 解壓nginx
# tar -zxvf nginx-1.10.3.tar.gz - 進(jìn)入nginx目錄
#cd nginx-1.10.3 - 對nginx的源碼進(jìn)行編譯
# ./configure - 開始編譯
# make - 繼續(xù)編譯
# make install - 查看nginx安裝的目錄
# whereis nginx它會告訴你nginx在哪,nginx的命令在/usr/local/nginx/sbin目錄下
nginx命令:
nginx命令開啟# ./nginx
停止# ./nginx -s stop
# ./nginx -s quit
重啟# ./nginx -s reload
開啟nginx # ./nginx 必須在nginx的安裝目錄下的sbi文件開啟,當(dāng)然也可全局配置
查看是否開啟nginx # ps aux|grep nginx
nginx配置
以下是nginx配置的部分參考
# http server
server {
listen 80;
server_name www.didiheng.com;
#charset koi8-r;
#access_log logs/host.access.log main;
access_log off; #緩存日志關(guān)閉
server_tokens off;
tcp_nopush on;
tcp_nodelay on;
gzip on; #gzip開啟
gzip_comp_level 6; #gzip比率
gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
proxy_connect_timeout 5; #緩存鏈接
proxy_read_timeout 60;
proxy_send_timeout 5;
proxy_buffer_size 16k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
location / {
root /www; #此處絕對地址
index index.html index.htm;
try_files $uri $uri/ /index.html; //使用客戶端路由需配置
rewrite ^(.*)$ https://$host$1 permanent; /強制定向https
}
#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;
}
#https server
server {
listen 443 ssl;
server_name www.didiheng.com;
ssl_certificate server.crt;
ssl_certificate_key server.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
access_log off;
server_tokens off;
tcp_nopush on;
tcp_nodelay on;
expires epoch;
gzip on;
gzip_comp_level 6;
gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
proxy_connect_timeout 5;
proxy_read_timeout 60;
proxy_send_timeout 5;
proxy_buffer_size 16k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
location / {
root /www;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
}
}
在以上配置中我直接將https開啟了,若沒有相關(guān)的ssl配置,請將https服務(wù)注釋 使用 # 即可
修改之后重啟nginx
# ./nginx -s reload
使用serverIP或域名訪問 訪問
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
windows10 系統(tǒng)配置nginx文件服務(wù)器的圖文教程
這篇文章主要介紹了windows10 系統(tǒng)配置nginx文件服務(wù)器的圖文教程,本文圖文并茂給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下2019-12-12
Nginx負(fù)載均衡之upstream模塊簡介與使用詳解
nginx有一個最大的功能就是可以實現(xiàn)服務(wù)器的負(fù)載均衡,下面這篇文章主要給大家介紹了關(guān)于Nginx負(fù)載均衡之upstream模塊簡介與使用的相關(guān)資料,文中通過實例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-09-09
Nginx反向代理出現(xiàn)502?Bad?Gateway問題解決
在配置Nginx反向代理時遇到502 Bad Gateway錯誤,經(jīng)過排查發(fā)現(xiàn)是SSL握手問題,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2024-10-10

