JAVA和Nginx 教程大全

网站首页 > 精选教程 正文

Nginx基础部署说明,小白自用

wys521 2024-09-07 03:09:37 精选教程 28 ℃ 0 评论

1、下载

下载Nginx软件,进行解压。

2、配置nginx.conf

下面需要修改nginx.conf来实现直接使用http://localhost/upload/1.jpg访问服务器的图片的功能(这里本地就是服务器)。


目前我已知的nginx支持的有两种:1、配置root,2、配置alias


本地测试的图片放在nginx目录的html文件夹下面




第一种:

root:会网访问url后面拼接配置的路径

配置实例如下:

location /images/ {
    root html;
    index  index.html index.htm;
 }

对于这种配置,直接访问http://localhost/images/1.jpg即可访问到images文件夹下的图片。

(访问路径会被指向http://localhost/html/images/1.jpg)

第二种:

alias:直接指向目标文件的物理地址。

配置实例如下:

location /upload/ {
    alias E:/ljdworkspace/nginx-1.12.2/nginx-1.12.2/html/images/;
    autoindex on;
 }

对于这种配置,直接访问http://localhost/upload/1.jpg 即可访问到E盘指定目录下的images文件夹里的图片。

————————————————

参照如下:使用第一种方式root配置

#user  nobody;
worker_processes  1; #nginx开启的进程数,一般为cpu内核的整数倍

#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;
#指定最大可以同时接收的连接数量,这里一定要注意,最大连接数量是和worker processes共同决定的。
#multi_accept on;配置指定nginx在收到一个新连接通知后尽可能多的接受更多的连接
#use epoll;配置指定了线程轮询的方法,如果是linux2.6+,使用epoll,如果是BSD如Mac请使用Kqueue

}


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;#配置on让sendfile发挥作用,将文件的回写过程交给数据缓冲去去完成,而不是放在应用中完成,这样的话在性能提升有有好处

    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       8090; #配置端口
        server_name  images.shinelon.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location /images/ {
            root   C:\images;
            index  index.html index.htm;
        }
	location /imgs/ {
            root   C:\imgs;
            index  index.html index.htm;
        }
	location /imgs2/ {
            root   C:\images2;
            index  index.html index.htm;
        }
      # 上面配置了三个文件夹,在同一个nginx中,根据images、imgs、imgs2可以访问各自下面的图片信息
      #这样就可以配置多盘访问,如对D、E、F盘或者内网挂载的网盘进行访问。

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

}


2021年5月7日 记。

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表