Install Nginx under Linux and configure a picture server

Source: Internet
Author: User

  First Installing the Nginx installation Environment

Nginx is a C language development, it is recommended to run on Linux , this tutorial uses Centos6. 5 as the installation environment.

-GCC

installation nginx need to download the source code to compile, compile dependent gcc Environment, if there is no gcc Environment, need to install gcc :

Yum Install gcc-c++

-PCRE

PCRE (perl Compatible Regular Expressions) is a perl Library that includes a perl - compatible regular expression library . the Nginx http module uses pcre to parse the regular expression , so it needs to be installed on Linux Pcre Library.

Yum install-y pcre Pcre-devel

Note:pcre-devel is A two-time development library developed using PCRE. nginx also needs this library.

-Zlib

The Zlib Library provides a number of ways to compress and decompress, and Nginx uses zlib to gzip the contents of the HTTP package , so you need to install the zlib library on Linux .

Yum install-y zlib Zlib-devel

--OpenSSL

OpenSSL is a strong Secure Sockets Layer Cipher library that includes key cryptographic algorithms, common key and certificate encapsulation management functions , and SSL protocols, and provides a rich set of applications for testing or other purposes.

Nginx not only supports the HTTP protocol, but also supports HTTPS(that is , transmitting httpon the SSL protocol), so you need to Linux installation OpenSSL Library.

Yum Install-y OpenSSL Openssl-devel
then install Nginx

to the Nginx official website Download tar.gz format installation package, here download is nginx-1.10.3 version, the environment uses the CentOS the virtual machine

1,upload the installation package, unzip, command tar-zxvf nginx-1.10.3.tar.gz

2, custom Create a folder as nginx installation directory, here under the home to create Nginx folder

3. Execute the ./configure--prefix=/home/nginx Commandunder the extracted folder (nginx-1.10.3).  
Configuring the installation environment will Nginx installed under the /home/nginx ;

4. Compile: Execute make and make install command under Unpacked folder

Execute make

Then execute the Make install

5, the default use of the Nginx port is thefirst, here directly to the nginx Port changed to 8088,

vi/home/nginx/conf/nginx.conf , modify the server 's port, and configure a picture server

#user nobody;worker_processes1; #error_log logs/Error.log, #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid;events {worker_connections1024;}    HTTP {include mime.types; Default_type Application/octet-stream; #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 logs/Access.log Main;    Sendfile on;    #tcp_nopush on; #keepalive_timeout0; Keepalive_timeout65;    #gzip on; server {Listen8080; #写内网端口, Access server_name localhost using an extranet port for map access; #charset Koi8-R; #access_log logs/Host.access.log Main; Location~ .*\. (gif|jpg|jpeg|PNG) $ {expires 24h; Root/home/images/; #指定图片存放路径 Access_log/home/nginx/logs/images.log; #图片 log path proxy_store on;              Proxy_store_access USER:RW GROUP:RW ALL:RW; Proxy_temp_path/home/images/; #代理临时路径 proxy_redirect off; Proxy_set_header Host127.0.0.1; Proxy_set_header X-real-IP $remote _addr; Proxy_set_header X-forwarded-For $proxy _add_x_forwarded_for;              Client_max_body_size 10m;              Client_body_buffer_size 1280k; Proxy_connect_timeout900; Proxy_send_timeout900; Proxy_read_timeout900;              Proxy_buffer_size 40k; Proxy_buffers40320k;              Proxy_busy_buffers_size 640k;              Proxy_temp_file_write_size 640k; if( !-e $request _filename) {Proxy_pass http://127.0.0.1:8080; #代理访问地址, consistent with the above ports}} Location/{root HTML;        Index index.html index.htm; } #error_page404/404. html; # REDIRECT Server error pages to theStaticPage/50x.html # Error_page500 502 503 504/50x.html; Location= /50x.html {root html; } # Proxy The PHP scripts to Apache listening on127.0.0.1:80# #location~\.php$ {# Proxy_pass http://127.0.0.1;#} # Pass the PHP scripts to FastCGI server listening on127.0.0.1:9000# #location~\.php$ {# root HTML; # Fastcgi_pass127.0.0.1:9000;        # Fastcgi_index index.php; # Fastcgi_param Script_filename/Scripts$fastcgi_script_name;        # include Fastcgi_params; #} # Deny access to. htaccess files,ifApache ' s document Root # concurs with Nginx ' s one# #location~ /\.ht {# deny all; #}} # Another virtual host using mix of IP-, name-, and port-based configuration # #server {# listen8000; # Listen Somename:8080;    # server_name somename alias Another.alias; # Location/{# root HTML;    # index index.html index.htm; #} #} # HTTPS Server # #server {# listen443SSL;    # server_name localhost;    # ssl_certificate Cert.pem;    # Ssl_certificate_key Cert.key;    # Ssl_session_cache shared:ssl:1m;    # ssl_session_timeout 5m; # Ssl_ciphers High:!anull:!MD5;    # ssl_prefer_server_ciphers on; # Location/{# root HTML;    # index index.html index.htm; #    }    #}}

under server listen , change the port to 8088andadd a location configuration to access the picture file, This string configuration has the # number in front of the comment out can be deleted, lest looks long and disorderly.

6. Start command: /home/nginx/sbin/nginx-c/home/nginx/conf/nginx.conf
Open the firewall corresponding to the port statement access,8088, of course, can also directly shut down the firewall.  
if the nginx.conf configuration is modified, a reboot is required to take effect, command:/home/nginx/sbin/nginx-s Reload

7, Access.  
Enter the ifconfig command to view the virtual machine IP, test:

under the /home/images , a picture is delegated, test access:

Install Nginx under Linux and configure a picture server

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.