CentOS7配置Nginx默认首页过程解析
找到nginx的安装目录:
whereis nginx
进入nginx/html目录:
cd /usr/local/nginx/html/
进入nginx/conf目录:
cd ..
cd conf
查看nginx.conf (nginx的核心配置文件):
vim 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;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
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
查看其中的server:
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
● listen:待监听的端口号;
● server_name:请求时的IP,如果在域名系统中进行了DNS解析(已经将IP和域名进行了映射),也可以直接使用域名来进行访问;
● location:映射。
location / {
root html;
index index.html index.htm;
}
○ / :找到根目录,也就是下面的root;
○ html:相对文件夹的位置(相对的是和conf目录在同一级目录);
○ index index.html index.htm:配置一个默认的首页index.html和index.htm。
修改当前.conf文件的listen值为88:
server {
listen 88;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
保存文件,进入 nginx/sbin 目录
重新加载配置文件:
./nginx -s reload
浏览器访问:
http://[ip地址]:88
注:如果是在云服务器上操作,在访问之前需要确认新修改的这个端口,是否已在安全组中进行开放。
本文来自博客园,作者:赵雯_后端开发工程师,转载请注明原文链接:https://www.cnblogs.com/ybqdren/p/15640993.html