Linux搭建Ngnix教程

一、安装nginx服务器

 

二、关于图片服务器配置

进入配置文件目录

[java] view plain copy

  1. cd /usr/local/nginx/conf/  

nginx的默认配置文件nginx.config

[java] view plain copy

  1. #user  nobody;  

  2. worker_processes  1;  

  3.   

  4. #error_log  logs/error.log;  

  5. #error_log  logs/error.log  notice;  

  6. #error_log  logs/error.log  info;  

  7.   

  8. #pid        logs/nginx.pid;  

  9.   

  10.   

  11. events {  

  12.     worker_connections  1024;  

  13. }  

  14.   

  15.   

  16. http {  

  17.     include       mime.types;  

  18.     default_type  application/octet-stream;  

  19.   

  20.     #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '  

  21.     #                  '$status $body_bytes_sent "$http_referer" '  

  22.     #                  '"$http_user_agent" "$http_x_forwarded_for"';  

  23.   

  24.     #access_log  logs/access.log  main;  

  25.   

  26.     sendfile        on;  

  27.     #tcp_nopush     on;  

  28.   

  29.     #keepalive_timeout  0;  

  30.     keepalive_timeout  65;  

  31.   

  32.     #gzip  on;  

  33.   

  34.     server {  

  35.         listen       80;  

  36.         server_name  localhost;  

  37.   

  38.         #charset koi8-r;  

  39.   

  40.         #access_log  logs/host.access.log  main;  

  41.   

  42.         location / {  

  43.             root   html;  

  44.             index  index.html index.htm;  

  45.         }  

  46.   

  47.         #error_page  404              /404.html;  

  48.   

  49.         # redirect server error pages to the static page /50x.html  

  50.         #  

  51.         error_page   500 502 503 504  /50x.html;  

  52.         location = /50x.html {  

  53.             root   html;  

  54.         }  

  55.   

  56.         # proxy the PHP scripts to Apache listening on 127.0.0.1:80  

  57.         #  

  58.         #location ~ \.php$ {  

  59.         #    proxy_pass   http://127.0.0.1;  

  60.         #}  

  61.   

  62.         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000  

  63.         #  

  64.         #location ~ \.php$ {  

  65.         #    root           html;  

  66.         #    fastcgi_pass   127.0.0.1:9000;  

  67.         #    fastcgi_index  index.php;  

  68.         #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;  

  69.         #    include        fastcgi_params;  

  70.         #}  

  71.   

  72.         # deny access to .htaccess files, if Apache's document root  

  73.         # concurs with nginx's one  

  74.         #  

  75.         #location ~ /\.ht {  

  76.         #    deny  all;  

  77.         #}  

  78.     }  

  79.   

  80.   

  81.     # another virtual host using mix of IP-, name-, and port-based configuration  

  82.     #  

  83.     #server {  

  84.     #    listen       8000;  

  85.     #    listen       somename:8080;  

  86.     #    server_name  somename  alias  another.alias;  

  87.   

  88.     #    location / {  

  89.     #        root   html;  

  90.     #        index  index.html index.htm;  

  91.     #    }  

  92.     #}  

  93.   

  94.   

  95.     # HTTPS server  

  96.     #  

  97.     #server {  

  98.     #    listen       443 ssl;  

  99.     #    server_name  localhost;  

  100.   

  101.     #    ssl_certificate      cert.pem;  

  102.     #    ssl_certificate_key  cert.key;  

  103.   

  104.     #    ssl_session_cache    shared:SSL:1m;  

  105.     #    ssl_session_timeout  5m;  

  106.   

  107.     #    ssl_ciphers  HIGH:!aNULL:!MD5;  

  108.     #    ssl_prefer_server_ciphers  on;  

  109.   

  110.     #    location / {  

  111.     #        root   html;  

  112.     #        index  index.html index.htm;  

  113.     #    }  

  114.     #}  

  115.   

  116. }  

配置图片服务器

在配置文件server{}中location /{} 修改配置:

  1.  #默认请求  

  2. location / {  

  3.    root  /home/ftpuser/nginx;#定义服务器的默认网站根目录位置  

  4.    index index.html index.htm;#定义首页索引文件的名称  

  5. }  

其中:/home/ftpuser/nginx;为创建FTP服务账户ftpuser的根目录下的nginx目录

注意:

            1、修改完后重启nginx(强制关闭:pkill -9 nginx,开启:/usr/local/nginx/sbin/nginx,查看:netstat -tulnp | grep ':80 ')

            2、修改完后给目录位置赋予权限(chmod -R 777 /home/ftpuser/nginx)

 

三、FTP服务的安装与启动

 

1、安装vsftpd组件

vsftpd组件为Linux的FTP服务组件,安装方式为在线安装。

[root@localhost ~]# yum -y install vsftpd

安装完后,有/etc/vsftpd/vsftpd.conf 文件,是vsftp的配置文件。

2、添加一个ftp用户

此用户就是用来登录ftp服务器用的。

[root@localhost ~]# useradd ftpuser  

 

这样一个用户建完,可以用这个登录,记得用普通登录不要用匿名了。登录后默认的路径为 /home/ftpuser.

为这个ftp账户添加密码

[root@localhost ~]# passwd ftpuser  

输入两次密码后修改密码。

 

 

3、设置开机启动vsftpd ftp服务

[root@localhost ~]# chkconfig vsftpd on

 

4、部署验证

在www下面放一张图片a.jpg

测试访问:http://xxx.xxx.xxx.xxx/a.jpg

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值