溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Nginx修改靜態(tài)文件訪問路徑

發(fā)布時(shí)間:2020-07-29 18:28:44 來源:網(wǎng)絡(luò) 閱讀:656 作者:ywb_4185 欄目:建站服務(wù)器

外網(wǎng)用戶訪問服務(wù)器的 Web 服務(wù)由 Nginx 提供,Nginx 需要配置靜態(tài)資源的路徑信息才能通過 url 正確訪問到服務(wù)器上的靜態(tài)資源。
打開 Nginx 的默認(rèn)配置文件

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

將service中添加如下配置

root 靜態(tài)文件根路徑

示例代碼:/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端口訪問時(shí)是以設(shè)置好的路徑為根路徑,可以依舊不同靜態(tài)文件的路徑訪問靜態(tài)文件

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI