ngnix 搭建


首次接触ngnix  http 将所做的内容记录一下

1. 下载所需要资源,我是下载到/home/code/Documents/webserver/ 目录下

1)openssl 
./config --prefix=/usr/local/openssl
make 
sudo make install

2.pcre
http://nchc.dl.sourceforge.net/project/pcre/pcre/8.10/pcre-8.10.tar.gz
./configure
make
sudo make install

3. zlib
./configure
make
sudo make install

4.ngnix
http://nginx.org/download/nginx-1.9.1.tar.gz
./configure --prefix=/usr/local/nginx --with-pcre=/home/code/Documents/webserver/pcre-8.10 --with-zlib=/home/code/Documents/webserver/zlib-1.2.8 --with-openssl=/home/code/Documents/webserver/openssl-1.0.0e --with-http_stub_status_module --with-http_ssl_module


3.编译之后运行 ;

/sbin/ngnix ;


4.简单修改配置文件:

conf/nginx.conf

server {
        listen       8085;    // 端口号 
        server_name  localhost;  本机IP 

        #charset koi8-r;
        #access_log  logs/host.access.log  main;

        location / {
            root   html;  //存放文件的目录
            index  index.html index.htm;
        }


5.网页访问  :(这里说明遇到的问题,一定要加端口号)


查看本机IP 比如  192.168.192.128

http:// 192.168.192.128:8085/ 

提示 下面内容证明访问成功;

Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.


6.怎么访问文件 :
比如我在html 的目录下放video.mp4  
访问的时候直接 输入: http://192.168.192.128:8060/video.mp4  即可 ;

就可以直接访问网页播放视频
如果建立子目录的话,在html下建立audio ,防止文件即可;
http://192.168.192.128:8060/audio/libai.mp3;

以上仅供参考,个人学习使用;

参考:
http://www.2cto.com/os/201406/310462.html
http://www.linuxidc.com/Linux/2013-09/89768.htm
http://jingyan.baidu.com/article/2fb0ba404f814e00f2ec5f9e.html
http://blog.youkuaiyun.com/ihelloworld/article/details/7029796




### 使用 Nginx 搭建 WebDAV 服务器 #### 安装必要的模块和支持软件包 为了使 Nginx 支持 WebDAV 功能,可能需要编译安装带有 `--with-http_dav_module` 的 Nginx 或者添加第三方扩展模块如 `nginx-dav-ext-module` 来增强其功能[^2]。 #### 创建用于 WebDAV 访问的用户账号 建议创建专门的服务账户来运行 Nginx 和处理 WebDAV 请求。这可以通过 Linux 用户管理命令完成: ```bash groupadd nginx useradd -c "nginx user" -d /var/cache/nginx -s /sbin/nologin nginx ``` 此步骤有助于提高安全性并遵循最小权限原则[^3]。 #### 设置认证机制 为了让客户端能够安全地连接到 WebDAV 服务,应该配置基本的身份验证方式。可以利用 OpenSSL 工具生成加密后的密码文件供 Nginx 使用: ```bash echo "username:$(openssl passwd password)" >/etc/nginx/user.passwd ``` 这里替换 `username` 和 `password` 为实际使用的用户名和密码[^4]。 #### 编辑 Nginx 配置文件 接下来,在 Nginx 中定义一个新的虚拟主机或修改现有站点配置以启用 WebDAV 协议的支持。以下是典型的配置片段示例: ```nginx server { listen 80; server_name your_domain; location /webdav/ { alias /var/www/webdav/; auth_basic "Restricted Area"; auth_basic_user_file /etc/nginx/user.passwd; client_body_temp_path /tmp; client_max_body_size 1G; dav_methods PUT DELETE MKCOL COPY MOVE; dav_ext_methods PROPFIND OPTIONS LOCK UNLOCK; create_full_put_path on; autoindex on; } } ``` 这段配置指定了 `/webdav/` 路径下的资源可通过 HTTP 方法上传下载,并启用了详细的 DAV 命令集以便更好地兼容各种客户端应用[^1]。 #### 测试与重启 Nginx 保存更改后测试配置的有效性,并重新加载 Nginx 使其生效: ```bash sudo nginx -t sudo systemctl reload nginx ``` 此时应当可以在浏览器或其他支持 WebDAV 的应用程序里尝试访问 http://your_domain/webdav 并执行相应的文件操作了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值