一.??Nginx安裝
1.更新軟件包列表:打開終端,并使用以下命令更新軟件包列表:
sudo yum update
2.安裝 EPEL 存儲庫:EPEL 存儲庫提供了額外的軟件包,其中包括 Nginx。使用以下命令安裝 EPEL 存儲庫:sudo yum install epel-release
3.安裝 Nginx:使用以下命令安裝 Nginx:sudo yum install nginx
4.啟動 Nginx:安裝完成后,可以使用以下命令啟動 Nginx 服務:
sudo systemctl start nginx
5.配置開機自啟:使用以下命令將 Nginx 設置為開機自啟動:
sudo systemctl enable nginx
6.驗證安裝:打開 web 瀏覽器,并輸入服務器的 IP 地址或域名。如果一切正常,你將看到 Nginx 的默認歡迎頁面。Nginx 的配置文件通常位于
/etc/nginx/nginx.conf
或/etc/nginx/conf.d/default.conf
。根據(jù)你的需求,可以進行相應的修改。
二. 進入/etc/nginx/nginx.conf
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user root;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
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 /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location /var/ {
alias /var/;
autoindex on;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2 default_server;
# listen [::]:443 ssl http2 default_server;
# server_name _;
# root /usr/share/nginx/html;
#
# ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers PROFILE=SYSTEM;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# location / {
# }
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
}
修改location配置? 為自己訪問圖片的位置? ?第五行 user改為root
? ? ? ? location /var/ {
? ? ? ? ? ? ? ? alias /var/;? # 訪問圖片位置
? ? ? ? ? ? ? ? autoindex on;
? ? ? ? ? ? }
重新啟動 Nginx 服務,使配置更改生效??梢允褂靡韵旅顏碇貑?Nginx:
sudo service nginx restart
文章來源:http://www.zghlxwxcb.cn/news/detail-634526.html
?我們就可以看到自己的放置的圖片文章來源地址http://www.zghlxwxcb.cn/news/detail-634526.html
到了這里,關于[Linux服務器 ] nginx 配置圖片靜態(tài)訪問方法的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!