Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure nginx and tomcat to access pictures and static pages

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

In this article Xiaobian for you to introduce in detail "nginx and tomcat access pictures and static pages how to configure", detailed content, clear steps, details handled properly, I hope that this "nginx and tomcat access pictures and static pages how to configure" article can help you solve doubts, following the editor's ideas slowly in-depth, together to learn new knowledge bar.

The first method: under nginx configuration

1. Create a file path:

[root@localhost /] # mkdir / data/soft/ [root@localhost ~] # cd / data/soft/ [root@localhost soft] # mkdir html images

2. Put the picture under the images directory

[root@localhost soft] # cd images/ [root@localhost images] # ll Total usage 80-rw-r--r--. 1 root root 9503 April 25 17:06 thpzfulfjn.jpg-rw-r--r--. 1 root root 16083 April 25 17:06 thr2c5vcmz.jpg-rw-r--r--. 1 root root 12218 April 25 17:06 thrg3yx53t.jpg-rw-r--r--. 1 root root 15048 April 25 17:06 thsuf51vtr.jpg-rw-r--r--. 1 root root 21799 April 25 17:06 thvwslf8ze.jpg

3. Put a test file in the html directory

[root@localhost html] # cat index.html this is test page!

4. Install nginx and start

Choose yum or compile to see what you like. I choose to compile and make my own installation module.

Extract the three packages of pcre-8.34.tar.gz zlib-1.2.8.tar.gz openssl-1.0.1g.tar.gz and install them

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

Install nginx

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

Compile and install

Make & & make install groupadd www useradd-g www www

Modify nginx configuration file

[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/;# specifies the image storage path access_log / data/soft/nginx/logs/images.log;# log storage path proxy_store on Proxy_store_access user:rw group:rw all:rw; proxy_temp_path / data/soft/images/;# image access path 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;# default port 80}} location / {root / data//soft/html; # html access path index index.html index2.htm; # html file name}} error_page 404 / 404.html

5. You can test it at this time.

First, the html page.

Looking at the picture.

Obviously, static pages and pictures can be accessed successfully under nginx settings, so let's start with tomcat access settings

The second method: tomcat

1. View the jdk version

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)

2. Decompress tomcat and start it

Tar-xvf apache-tomcat-8.5.30.tar.gz [root@localhost tomcat] # sh bin/startup.sh

3. Can you access the local test

4, the above is normal, then put the page folder under wepapps, notice that there are inde.html pages in the html folder.

[root@localhost soft] # cp-rp html/ / data/soft/tomcat/webapps/

Test access to the html page

Continue to put the pictures folder under wepapps, where there are pictures under images.

[root@localhost images] # cp-rp / data/soft/images/ / data/soft/tomcat/webapps/

Visit the following directly on the browser

After reading this, the article "how to configure nginx and tomcat access pictures and static pages" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it to understand it. If you want to know more about related articles, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report