linux中怎么即时设置一个静态文件服务器

2023-04-12 09:54:00 设置 静态 即时

Linux中怎么即时设置一个静态文件服务器

一、安装nginx

1、下载安装包

wget http://nginx.org/download/nginx-1.12.2.tar.gz

2、解压安装包

tar -zxvf nginx-1.12.2.tar.gz

3、进入解压目录

cd nginx-1.12.2

4、配置安装

./configure

5、编译安装

make && make install

6、启动nginx

/usr/local/nginx/sbin/nginx

7、查看nginx进程

ps -ef | grep nginx

8、设置开机启动

echo "/usr/local/nginx/sbin/nginx" >> /etc/rc.local

二、配置nginx

1、修改nginx配置文件

vim /usr/local/nginx/conf/nginx.conf

2、在http节点下添加如下配置

server {

listen 80;

server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {

root /usr/local/nginx/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 /usr/local/nginx/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;

#}

}

3、修改完成后保存退出

4、重新加载nginx配置

/usr/local/nginx/sbin/nginx -s reload

三、搭建静态文件服务器

1、创建文件目录

mkdir -p /usr/local/nginx/html

2、将需要访问的文件放入该目录下

3、访问文件

在浏览器中输入http://ip地址/文件名即可访问

相关文章