nginx搭文件服务器

安装nginx

yum -y install nginx

搭建文件服务器

1.改为root用户

原来的nginx.conf里,第一行是

user ngix;  # 不同版本的不一样

改为

user root;

2.加一个server

①配置文件位置

[root@VM_0_9_centos ~]# find / -name nginx.conf
/var/opt/gitlab/nginx/conf/nginx.conf
/opt/gitlab/embedded/lib/ruby/gems/2.4.0/gems/unicorn-5.1.0/examples/nginx.conf
/opt/gitlab/embedded/conf/nginx.conf  
/etc/nginx/nginx.conf  # 这个是要找的文件

②html目录

/usr/share/nginx/html  # 默认的

③在原来的nginx.conf里加一个server配置

配置写在http { } 里面,与其他server 同级别。

	autoindex on;# 显示目录
	autoindex_exact_size on;# 显示文件大小
	autoindex_localtime on;# 显示文件时间

	server {
		listen       8080 default_server;
		listen       [::]:8080 default_server;
		server_name  _;
		#root         /usr/share/nginx/html;
		root         /data/;

		location / {
		}

		error_page 404 /404.html;
			location = /40x.html {
		}

		error_page 500 502 503 504 /50x.html;
			location = /50x.html {
		}
	}

参考:https://www.jianshu.com/p/95602720e7c8

3.启动

service nginx start
service nginx stop 
service nginx restart   # 重启
nginx -s reload   # 修改配置后重启,或者使用reload重载配置文件

4.访问界面

在这里插入图片描述

5.完整的nginx配置参考


user root;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/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  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;
        include /etc/nginx/conf.d/*.conf;

        location / {
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

	autoindex on;# 显示目录
	autoindex_exact_size on;# 显示文件大小
	autoindex_localtime on;# 显示文件时间

	server {
		listen       6868 default_server;
		listen       [::]:6868 default_server;
		server_name  _;
		#root         /usr/share/nginx/html;
		root         /;

		location / {
		}

		error_page 404 /404.html;
			location = /40x.html {
		}

		error_page 500 502 503 504 /50x.html;
			location = /50x.html {
		}
	}

}

  • 11
    点赞
  • 81
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Keepalived可以与Nginx配使用,以提供高可用性和负载均衡的功能。在配置Keepalived和Nginx之前,需要先下载和安装Nginx。 首先,你可以使用以下命令下载Nginx的源代码包: ``` wget http://nginx.org/download/nginx-1.14.0.tar.gz [1] ``` 接下来,安装一些必要的软件包和工具: ``` yum -y install vim lrzsz ntpdate wget [2] ntpdate ntp1.aliyun.com # 同步时间 ``` 然后,解压Nginx源代码包,并将其安装到指定目录: ``` tar -xf nginx-1.14.0.tar.gz -C /usr/local/ groupadd nginx # 创建nginx用户组 useradd -g nginx nginx # 创建nginx用户 [3] ``` 完以上步骤后,你就可以开始配置Keepalived和Nginx了。Keepalived可以作为一个高可用性解决方案,通过提供虚拟IP地址和服务监控来实现故障切换。Nginx可以作为一个反向代理和负载均衡器,通过将请求分发给多个后端服务器来提高性能和可用性。 在配置中,你需要注意将Keepalived的状态设置为备份状态,在Keepalived的配置文件中进行相应的设置。具体的配置内容和步骤可以根据你的需求和环境进行调整。 总结起来,Keepalived可以与Nginx配使用,以提供高可用性和负载均衡的功能。你可以根据上述步骤开始配置Keepalived和Nginx,并根据需要进行相应的调整。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [nginx+keepalived高可用详解配置](https://blog.csdn.net/weixin_45894220/article/details/118808882)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值