搭建Nginx图片服务器(Linux)

3 篇文章 0 订阅
1 篇文章 0 订阅

1.到nginx官网(http://nginx.org/en/download.html)下载压缩包,建议下载稳定的版本

2. tar zxf nginx-1.14.0.tar.gz 将文件解压

执行命令:

 

    ./configure  --prefix=/usr/local/nginx  --pid-path=/var/run/nginx/nginx.pid  --lock-path=/var/lock/nginx.lock  --error-log-path=/var/log/nginx/error.log  --http-log-path=/var/log/nginx/access.log   --with-http_gzip_static_module   --http-client-body-temp-path=/var/temp/nginx/client --http-proxy-temp-path=/var/temp/nginx/proxy --http-fastcgi-temp-path=/var/temp/nginx/fastcgi  --http-uwsgi-temp-path=/var/temp/nginx/uwsgi   --http-scgi-temp-path=/var/temp/nginx/scgi 

 

启动nginx服务器

    进入 cd   /usr/local/nginx/sbin下

    有个ngnix可执行文件

    执行 ./nginx   命令启动服务器

查看Nginx是否启动ps -aux|grep nginx

 

用浏览器访问,Nginx安装成功

配置图片存放及访问路径

 

#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 ~ \.(gif|jpg|jpeg|png|bmp|swf|gif|txt|doc|docx|xls|xlsx|ppt|pptx|pdf|zip|rar)$ {

            root   /var/ftp/pub/;

            autoindex on;

        }

 

        #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

        #

        #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;

        #}

    }

 

 

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

    #

    #server {

    #    listen       8000;

    #    listen       somename:8080;

    #    server_name  somename  alias  another.alias;

 

    #    location / {

    #        root   html;

    #        index  index.html index.htm;

    #    }

    #}

 

 

    # HTTPS server

    #

    #server {

    #    listen       443 ssl;

    #    server_name  localhost;

 

    #    ssl_certificate      cert.pem;

    #    ssl_certificate_key  cert.key;

 

    #    ssl_session_cache    shared:SSL:1m;

    #    ssl_session_timeout  5m;

 

    #    ssl_ciphers  HIGH:!aNULL:!MD5;

    #    ssl_prefer_server_ciphers  on;

 

    #    location / {

    #        root   html;

    #        index  index.html index.htm;

    #    }

    #}

 

}

 

修改完成后,进入到/usr/local/nginx/sbin 目录下

执行  ./nginx -s reload 从新启动nginx服务器

 

 

 

 

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Linux搭建Nginx服务器是一项非常重要的技能,因为Nginx是目前最流行的Web服务器之一。搭建Nginx服务器可以让您更好地托管您的网站或Web应用程序,并提供更高的性能。 需要注意的是,在搭建之前要确保您的Linux系统已经安装了Nginx软件。这里以Ubuntu Linux操作系统为例,您可以使用以下命令来安装Nginx: sudo apt-get update sudo apt-get install nginx 安装成功后,就可以开始配置Nginx服务器了。 第一步,打开Nginx配置文件。您可以使用以下命令打开默认配置文件: sudo nano /etc/nginx/sites-available/default 第二步,配置服务器。您需要在配置文件中设置您的网站目录、日志文件目录等信息。 例如: server { listen 80 default_server; root /var/www/html; index index.html index.htm index.nginx-debian.html; server_name yourdomain.com www.yourdomain.com; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; location / { try_files $uri $uri/ =404; } } 在此示例中,Nginx服务器将使用默认端口80,并将网站文件托管在/var/www/html目录中。 第三步,保存配置文件并重启Nginx服务器。在完成配置后,您可以按Ctrl + X,然后选择“Y”来保存文件。接着,在命令行中输入以下命令: sudo service nginx restart 此时,您的Nginx服务器已经搭建成功,并可以通过您的公网IP地址或域名进行访问。 总之,搭建Nginx服务器并不是一项非常困难的任务,只需要一些基本的Linux命令和Nginx配置的知识即可。通过学习和实践,您将可以轻松地搭建出您的Web服务器

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值