第一種方法:nginx設定下
1、建立檔案路徑:
[root@localhost /]# mkdir /data/soft/ [root@localhost ~]# cd /data/soft/ [root@localhost soft]# mkdir html images
2、在images目錄下方放入圖片
rrreee3、在html目錄下面放入一個測試檔
[root@localhost soft]# cd images/ [root@localhost images]# ll 总用量 80 -rw-r--r--. 1 root root 9503 4月 25 17:06 thpzfulfjn.jpg -rw-r--r--. 1 root root 16083 4月 25 17:06 thr2c5vcmz.jpg -rw-r--r--. 1 root root 12218 4月 25 17:06 thrg3yx53t.jpg -rw-r--r--. 1 root root 15048 4月 25 17:06 thsuf51vtr.jpg -rw-r--r--. 1 root root 21799 4月 25 17:06 thvwslf8ze.jpg
4、安裝nginx,並啟動
選用yum還是編譯看自己喜好,我選擇編譯,自己制定安裝模組
解壓縮pcre-8.34.tar.gz zlib-1.2.8.tar.gz openssl-1.0.1g.tar.gz三個套件並安裝
[root@localhost html]# cat index.html this is test page !!!!
安裝nginx
tar -zxvf pcre-8.34.tar.gz cd pcre-8.34 /configure && make && make install tar -zxvf zlib-1.2.8.tar.gz cd zlib-1.2.8 /configure && make && make install tar -zxvf openssl-1.0.1g.tar.gz cd openssl-1.0.1g /config && make && make install
編譯並安裝
tar -zxvf nginx-1.9.0.tar.gz cd nginx-1.9.0 #./configure --prefix=/data/soft/nginx \ --user=www \ --group=www \ --with-mail \ --with-mail_ssl_module \ --with-http_ssl_module \ --with-http_flv_module \ --with-http_dav_module \ --with-http_sub_module \ --with-http_spdy_module \ --with-http_realip_module \ --with-http_addition_module \ --with-http_gzip_static_module \ --with-http_stub_status_module \ --with-pcre=/data/src/pcre-8.34 \ --with-zlib=/data/src/zlib-1.2.8 \ --with-openssl=/data/src/openssl-1.0.1g
修改nginx設定檔
make && make install groupadd www useradd -g www www
5 、此時可以測試看看
先是html頁面
#在看看圖片
顯然,nginx設定下靜態頁面和圖片是可以存取成功的,下面開始tomcat存取設定
第二種方法:tomcat
1、查看jdk版本
[root@localhost nginx]# vim conf/nginx.conf server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location ~ .*\.(gif|jpg|jpeg|png)$ { expires 24h; root /data/soft/images/;#指定图片存放路径 access_log /data/soft/nginx/logs/images.log;#日志存放路径 proxy_store on; proxy_store_access user:rw group:rw all:rw; proxy_temp_path /data/soft/images/;#图片访问路径 proxy_redirect off; proxy_set_header host 127.0.0.1; client_max_body_size 10m; client_body_buffer_size 1280k; proxy_connect_timeout 900; proxy_send_timeout 900; proxy_read_timeout 900; proxy_buffer_size 40k; proxy_buffers 40 320k; proxy_busy_buffers_size 640k; proxy_temp_file_write_size 640k; if ( !-e $request_filename) { proxy_pass http://127.0.0.1;#默认80端口 } } location / { root /data//soft/html; #html访问路径 index index.html index2.htm; #html文件名称 } } error_page 404 /404.html;
2、解壓縮tomcat並啟動
java -version openjdk version "1.8.0_65" openjdk runtime environment (build 1.8.0_65-b17) openjdk 64-bit server vm (build 25.65-b01, mixed mode)
3、本地測試能不能訪問
4、 上面正常,那麼把頁面資料夾放到wepapps下面去,注意,html資料夾裡有inde.html頁面的。
tar -xvf apache-tomcat-8.5.30.tar.gz [root@localhost tomcat]# sh bin/startup.sh
測試訪問html頁面
繼續把圖片資料夾放到wepapps下面去,images下面是有圖片的。
[root@localhost soft]# cp -rp html/ /data/soft/tomcat/webapps/
直接在瀏覽器上存取如下
#
以上是nginx和tomcat存取圖片和靜態頁面怎麼配置的詳細內容。更多資訊請關注PHP中文網其他相關文章!

NGINX和Apache各有優劣,適合不同場景。 1.NGINX適合高並發和低資源消耗場景。 2.Apache適合需要復雜配置和豐富模塊的場景。通過比較它們的核心特性、性能差異和最佳實踐,可以幫助你選擇最適合需求的服務器軟件。

確認 Nginx 是否啟動的方法:1. 使用命令行:systemctl status nginx(Linux/Unix)、netstat -ano | findstr 80(Windows);2. 檢查端口 80 是否開放;3. 查看系統日誌中 Nginx 啟動消息;4. 使用第三方工具,如 Nagios、Zabbix、Icinga。

要關閉 Nginx 服務,請按以下步驟操作:確定安裝類型:Red Hat/CentOS(systemctl status nginx)或 Debian/Ubuntu(service nginx status)停止服務:Red Hat/CentOS(systemctl stop nginx)或 Debian/Ubuntu(service nginx stop)禁用自動啟動(可選):Red Hat/CentOS(systemctl disable nginx)或 Debian/Ubuntu(syst

如何在 Windows 中配置 Nginx?安裝 Nginx 並創建虛擬主機配置。修改主配置文件並包含虛擬主機配置。啟動或重新加載 Nginx。測試配置並查看網站。選擇性啟用 SSL 並配置 SSL 證書。選擇性設置防火牆允許 80 和 443 端口流量。

服務器無權訪問所請求的資源,導致 nginx 403 錯誤。解決方法包括:檢查文件權限。檢查 .htaccess 配置。檢查 nginx 配置。配置 SELinux 權限。檢查防火牆規則。排除其他原因,如瀏覽器問題、服務器故障或其他可能的錯誤。

在 Linux 中啟動 Nginx 的步驟:檢查 Nginx 是否已安裝。使用 systemctl start nginx 啟動 Nginx 服務。使用 systemctl enable nginx 啟用在系統啟動時自動啟動 Nginx。使用 systemctl status nginx 驗證啟動是否成功。在 Web 瀏覽器中訪問 http://localhost 查看默認歡迎頁面。

在 Linux 中,使用以下命令檢查 Nginx 是否已啟動:systemctl status nginx根據命令輸出進行判斷:如果顯示 "Active: active (running)",則 Nginx 已啟動。如果顯示 "Active: inactive (dead)",則 Nginx 已停止。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

Atom編輯器mac版下載
最受歡迎的的開源編輯器

Dreamweaver CS6
視覺化網頁開發工具

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能