小知识:CentOS6使用nginx搭建web网站服务的方法

利用CentOS6搭建简易的web服务

提示: 其中没有涉及到MySQl、MongoDB的安装和使用,包括docker容器等,使用nginx反向代理静态服务

centOS服务器

可以选用国外或者国内的服务器,这里只展示centOS系统配置,本人实在window系统下完成下列操作

选购一台合适的云服务器,系统为centOS

在window系统下安装xshell和xftp, 保证可以系统访问centOS系统

使用xshell连接上云服务器,使用超级管理员root登录

登录完成之后安装nginx

下面是需要下载的文件:

首先安装wget # yum install wget nginx以来与gcc的编译环境 # yum install gcc-c++ nginx的http模块需要使用pcre来解析正则表达式 # 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 进入nginx目录 #cd nginx-1.10.3 对nginx的源码进行编译 # ./configure 开始编译 # make 继续编译 # 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文件开启,当然也可全局配置

查看是否开启nginx # ps aux|grep nginx

nginx配置

以下是nginx配置的部分参考

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# http server
server {
listen    80;
server_name www.didiheng.com;
#charset koi8-r;
#access_log logs/host.access.log main;
access_log off; #缓存日志关闭
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开启了,若没有相关的ssl配置,请将https服务注释 使用 # 即可

修改之后重启nginx

?
1
# ./nginx -s reload

使用serverIP或域名访问 访问

github原址

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:https://www.jianshu.com/p/09d52505d852

声明: 猿站网有关资源均来自网络搜集与网友提供,任何涉及商业盈利目的的均不得使用,否则产生的一切后果将由您自己承担! 本平台资源仅供个人学习交流、测试使用 所有内容请在下载后24小时内删除,制止非法恶意传播,不对任何下载或转载者造成的危害负任何法律责任!也请大家支持、购置正版! 。本站一律禁止以任何方式发布或转载任何违法的相关信息访客发现请向站长举报,会员发帖仅代表会员个人观点,并不代表本站赞同其观点和对其真实性负责。本网站的资源部分来源于网络,如有侵权烦请发送邮件至:2697268773@qq.com进行处理。
建站知识

小知识:浅谈Linux下通过find命令进行rm文件删除的小技巧

2023-4-17 12:22:20

建站知识

小知识:Docker安装运行apache2服务器做图片服务器的方法

2023-4-17 12:26:49

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索