Nginx怎么改静态文件的访问路径?
admin
2023-02-05 16:40:03
0

外网用户访问服务器的 Web 服务由 Nginx 提供,Nginx 需要配置静态资源的路径信息才能通过 url 正确访问到服务器上的静态资源。
打开 Nginx 的默认配置文件

vim /usr/local/nginx/conf/nginx.conf

将service中添加如下配置

root 静态文件根路径

示例代码:/etc/nginx/nginx.conf

user nobody nobody;
worker_processes 2;
error_log /usr/local/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;

events
{   
    use epoll;
    worker_connections 6000;
}

http
{   
    include mime.types;
    default_type application/octet-stream;
    server_names_hash_bucket_size 3526;
    server_names_hash_max_size 4096;
    log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
    '$host "$request_uri" $status'
    '"$http_referer" "$http_user_agent"';
    sendfile on;
    tcp_nopush on;
    keepalive_timeout 30; 
        client_header_timeout 3m;
    client_body_timeout 3m;
    send_timeout 3m;
    connection_pool_size 256;
    client_header_buffer_size 1k;
    large_client_header_buffers 8 4k;
    request_pool_size 4k;
    output_buffers 4 32k;
    postpone_output 1460;
    client_max_body_size 10m;
    client_body_buffer_size 256k;
    client_body_temp_path /usr/local/nginx/client_body_temp;
    proxy_temp_path /usr/local/nginx/proxy_temp;
    fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
    fastcgi_intercept_errors on;
    tcp_nodelay on;
    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 8k;
    gzip_comp_level 5;
    gzip_http_version 1.1;
    gzip_types text/plain application/x-javascript text/css text/htm application/xml;
        server
        {
            listen 80 default;
            server_name _;
            root /var/ftp/source;
        }
        include /usr/local/nginx/conf/host/*.conf;
}

使用以下命令,重新加载Nginx

./nginx -s reload

再次通过IP和80端口访问时是以设置好的路径为根路径,可以依旧不同静态文件的路径访问静态文件

相关内容

热门资讯

成都深入实施“人工智能+”行动 成都深入实施“人工智能+”行动 到2027年实现人工智能核心产业规模突破2600亿元 华西都市报讯(...
原创 中... 说真的,看到欧洲科学家一本正经拿粪水浇菜做研究,最后还得出了个“安全无害、肥力充足”的结论,我第一反...
小米智能手环11 Active... IT之家 7 月 23 日消息,科技媒体 WinFuture 昨日(7 月 22 日)发布博文,分享...
胡塞武装袭击红海油轮,特朗普威... 据路透社报道,当地时间7月23日,也门胡塞武装表示已在红海袭击两艘沙特油轮,并称这两艘油轮违反该组织...
刚签就要黄了?特朗普:核能协议... 据彭博社报道,当地时间7月23日,美国总统特朗普表示,美国与沙特阿拉伯的民用核能合作协议能否落地,将...
原创 宇... 可观测宇宙的范围远远超出了以光年为单位的其年龄,因为在遥远光线传播的过程中,空间本身已经膨胀了。然而...
我国研发出具有“电子共振”结构... 【我国研发出具有“电子共振”结构的钙钛矿光伏电池】财联社7月22日电,苏州大学李耀文、陈先凯与东南大...
我国牵头制定,智能制造用例国际... 国际电工委员会智能制造系统委员会(IEC/SyC SM)近日发布《智能制造用例模板》国际标准。该标准...
一文看懂三星Z系列三款折叠新机... 【CNMO科技消息】近日,三星正式发布Z Fold8 Ultra、Z Fold8以及Z Flip8三...
4位菲尔兹奖得主有3位会说中文... 当地时间7月23日,2026年国际数学家大会在美国费城开幕,国际数学联盟在开幕式上正式公布第二十一届...