如果自己买了远程服务器和域名,准备开发好的纯静态网站,最后把这个静态的网站放到服务器上去,这样的话,任何人输入自己的域名,都可以看到自己的静态网站。
就是一台电脑,这台电脑的操作系统一般是Linux/Centos系统等,当然也有windows系统的,只不过windows系统的不太常见。
个人电脑上可以安装mySQL,在服务器上也可以安装mySQL。区别在于,用win7安装就是鼠标点击界面就行了。服务器安装,就要用命令行了,在一个黑框里面去敲命令。
index.html
,存在你个人电脑的桌面上,那么你要想让所有的人都看到你的这个页面,该怎么办呢,肯定要把这个index.html
这页面放到一个大家都能看到的地方。apt-get install nginx
就行yum install nginx -y
,注意一下自己的系统是哪一种(虽然都属于Linux系统,但是Ubuntu和CentOS不一样)。/etc/init.d/nginx start
就可以启动了(ubuntu)或者直接就是 nginx
(Centos)。ps -ef | grep nginx
,如果可以输出信息就说明nginx已经启动,如果没有任何信息输出,就说明nginx没有启动。whereis nginx
来找一找所有包含nginx
这个文件名的文件有哪些,你会找到不止一个文件,具体我们需要的是哪个,就要找那个(我的在/etc/init.d这里,有一个nginx);找到/etc/nginx
下面的配置文件,nginx.conf
、nginx.conf.default
,
主要是在Server{...}
这块区域的大括号里去改东西,打开这些文件的时候呢,会看到不少代码,代码前面带#号的都是注释,不用管,找到没有被注释的那个Server区域,在那个Server的大括号里去改,你要修改三个地方:
index.html
所在的文件夹,比如说,你可以在服务器电脑的根目录上新建一个test文件夹,把index.html
放进去,那么root后面的东西就是 /test
,/
就代表根目录,test代表文件夹名字kill nginx的PID
(ps -ef | grep nginx
查看nginx的PID),然后重新输入nginx
开启nginx就行了。#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;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /home/test; #这个是我自己的路径,需要换成你自己的
index index.html index.htm;
}
#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;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
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 /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name pkoml23.cn;
rewrite ^(.*)$ https://$host$1;
root /home/huiyi;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2 default_server;
# listen [::]:443 ssl http2 default_server;
# server_name _;
# root /usr/share/nginx/html;
#
# ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers PROFILE=SYSTEM;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# location / {
# }
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
server_name pkoml23.cn;
root /home/huiyi;
ssl_certificate "/etc/nginx/cert/cert.pem";
ssl_certificate_key "/etc/nginx/cert/cert.key";
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_ciphers PROFILE=SYSTEM;
ssl_prefer_server_ciphers on;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
好了,现在在在浏览器输入12.12.12.12.就可以看到你的index.html
的界面了,任何人在浏览器输入12.12.12.12也可以看到你写的index.html
的页面
最后是解析域名,把这个12.12.12.12的地址和一个www.xxxx.com或者www.yyyy.xyz之类的域名对应起来,这个网址你自己在你购买域名的地方去解析,比如我在阿里云买的域名,我就去当时阿里域名控制台那里,找到解析域名的地方,修改一下就可以了,注意,主机记录那里不要填www,也不要填任何东西,这个地方是个很隐蔽的坑,要注意。
记录值那里就填你的服务器电脑的IP,其他的地方默认就可以了,不用单独去选。这样的话,你在浏览器输入你买来的域名,就可以访问到index.html
的页面了。