有很多小伙伴想要建立一个自己的web站点,今天就给大家演示一下,下面我们就来聊聊关于有服务器了怎么搭建自己的网站?接下来我们就一起去了解一下吧!

有服务器了怎么搭建自己的网站(表白利器)

有服务器了怎么搭建自己的网站

有很多小伙伴想要建立一个自己的web站点,今天就给大家演示一下。

准备工作:

1、Nginx安装包;

2、Linux服务器;

3、PCRE安装包;

4、手。

方式一:手动编译安装1、安装编译库

yum -y install make zlib zlib-devel gcc-c libtool openssl openssl-devel

安装编译库,如果不安装,后续安装服务可能出现报错!

2、下载 安装PCRE

下载地址: http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz

[ooyy1102@localhost ~]$ cd /usr/local/src/ [ooyy1102@localhost src]$ su 密码: [root@localhost src]# wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz //下载pcre

[root@localhost src]# tar zxvf pcre-8.35.tar.gz 解压pcre压缩包 [root@localhost src]# cd pcre-8.35/ 进入pcre根目录 [root@localhost pcre-8.35]# ./configure [root@localhost pcre-8.35]# make && make install //配置编译

[root@localhost pcre-8.35]# pcre-config --version //安装完成后,查看已安装版本,出现对应版本号说明安装成功! 8.35

3、下载安装Nginx

下载 Nginx,下载地址:https://nginx.org/en/download.html

[root@localhost pcre-8.35]# pwd /usr/local/src/pcre-8.35 [root@localhost pcre-8.35]# cd /usr/local/src/ [root@localhost src]# wget http://nginx.org/download/nginx-1.6.2.tar.gz //下载nginx安装包

[root@localhost src]# tar zxvf nginx-1.6.2.tar.gz //解压

[root@localhost src]# cd nginx-1.6.2/ //进入nginx目录 [root@localhost nginx-1.6.2]# ./configure --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.35 [root@localhost nginx-1.6.2]# make && make install //配置变量编译

等待编译完成

[root@localhost nginx-1.6.2]# /usr/local/webserver/nginx/sbin/nginx -v nginx version: nginx/1.6.2

4、配置Nginx4.1 创建运行使用的账户www

[root@localhost nginx-1.6.2]# /usr/sbin/groupadd www 建立一个组www [root@localhost nginx-1.6.2]# /usr/sbin/useradd -g www www 添加一个用户www到www组 [root@localhost nginx-1.6.2]# pwd /usr/local/src/nginx-1.6.2

4.2 配置Nginx配置文件

[root@localhost nginx-1.6.2]# cd /usr/local/webserver/nginx/conf/ [root@localhost conf]# ls fastcgi.conf koi-utf nginx.conf uwsgi_params fastcgi.conf.default koi-win nginx.conf.default uwsgi_params.default fastcgi_params mime.types scgi_params win-utf fastcgi_params.default mime.types.default scgi_params.default [root@localhost conf]# cp nginx.conf nginx.conf.bak //备份nginx配置文件, [root@localhost conf]# gedit nginx.conf //可视化编辑gedit ,这里如果是ssh操作 建议使用vim [root@localhost conf]# /usr/local/webserver/nginx/sbin/nginx -t //校验 nginx: the configuration file /usr/local/webserver/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/webserver/nginx/conf/nginx.conf test is successful //提示成功和ok即可 [root@localhost conf]# /usr/local/webserver/nginx/sbin/nginx //启动nginx,这时候就可以在浏览器输入ip地址验证nginx是否启用成功了! [root@localhost conf]#

4.3 附nginx.conf文件内容(直接复制到文件编辑即可)

user www www; worker_processes 2; #设置值和CPU核心数一致 error_log /usr/local/webserver/nginx/logs/nginx_error.log crit; #日志位置和日志级别 pid /usr/local/webserver/nginx/nginx.pid; #Specifies the value for maximum file descriptors that can be opened by this process. worker_rlimit_nofile 65535; events { use epoll; worker_connections 65535; } 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'; #charset gb2312; server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_max_body_size 8m; sendfile on; tcp_nopush on; keepalive_timeout 60; tcp_nodelay on; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 64k; fastcgi_buffers 4 64k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 128k; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.0; gzip_comp_level 2; gzip_types text/plain application/x-javascript text/css application/xml; gzip_vary on; #limit_zone crawler $binary_remote_addr 10m; #下面是server虚拟主机的配置 server { listen 80;#监听端口 server_name localhost;#域名 index index.html index.htm index.php; root /usr/local/webserver/nginx/html;#站点目录 location ~ .*\.(php|php5)?$ { #fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico)$ { expires 30d; # access_log off; } location ~ .*\.(js|css)?$ { expires 15d; # access_log off; } access_log off; } }

5、配置站点主页

server { listen 80;#监听端口 server_name localhost;#域名 index index.html index.htm index.php; root /usr/local/webserver/nginx/html;#站点目录 location ~ ..(php|php5)?$ { #fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } location ~ ..(gif|jpg|jpeg|png|bmp|swf|ico)$ { expires 30d;

只要把我们的网站放在

/usr/local/webserver/nginx/html

目录下就可以了。

在没安装PHP等环境的时候,只支持普通的html网页哦。

/usr/local/webserver/nginx/sbin/nginx -s reload # 重新载入配置文件 /usr/local/webserver/nginx/sbin/nginx -s reopen # 重启 Nginx /usr/local/webserver/nginx/sbin/nginx -s stop # 停止 Nginx

方式二:宝塔面板一键安装部署

安装脚本:

yum install -y wget && wget -O install.sh http://download.bt.cn/install/install_6.0.sh && sh install.sh ed8484bec

具体可以看我之前的文章和视频哦:

https://www.toutiao.com/article/7098884541569401359/

,