search
HomeBackend DevelopmentPHP TutorialInstallation and configuration examples of Nginx under Windows

This article mainly shares with you the installation and configuration examples of Nginx under Windows. I hope it can help you.

1. Introduction to Nginx

1. What is Nginx

Nginx is a lightweight web server and a reverse proxy server

2. What can Nginx do?

① Can directly support Rails and PHP programs
② Can be used as an HTTP reverse proxy server
③ As a load balancing server
④ As a mail proxy server
⑤Help realize the separation of dynamic and static front-end

3.Nginx features

  • High stability

  • High performance

  • Low resource usage

  • Rich functions

  • Modular structure

  • Support hot deployment

2. Nginx installation

1. Download: http://nginx.org/download/nginx-1.10.2.zip

2. Decompress

3. Run nginx.exe: run by double-clicking the icon or cmd command line

3. Nginx common commands

1. Test configuration file

nginx.exe under the installation path -t

2. Start command

nginx.exe under the installation path

3. Stop command

nginx.exe under the installation path -s stop,
Or: nginx.exe -s quit

4. Restart command

nginx.exe under the installation path - s reload

5. View process command

ps -ef |grep nginx

6. Smooth restart

kill -HUP [Nginx main process number ( That is, check the PID found by the process command)】

7. Increase firewall access permissions

①sudo vim /etc/sysconfig/iptables
②-A INPUT -p tcp -m state – state NEW
-m tcp –dport 80 -j ACCEPT
③Save and exit
④Restart the firewall sudo service iptables restart

4. Nginx virtual domain name configuration and test verification

Configuration steps:

1. Edit sudo vim /usr/local/nginx/conf/nginx.conf
①Add include vhost/*.conf;
②Save and exit

Installation and configuration examples of Nginx under Windows

2. Create a new vhost folder in the /usr/local/nginx/conf/ directory:
That is: /user/local/nginx/conf/vhost

3. Create a domain name forwarding configuration File

image.hcxjingdong.com.conf:转向目录的反向代理:
server {
    listen 80;
    autoindex off;
    server_name image.hcxjingdong.com;
    access_log c: /access.log combined; index index.html index.htm index.jsp index.php; #error_page 404 /
    404. html;
    if ($query_string~ * ".*[\;'\].*") {
        return 404;
    }
    location~/(mmall_fe|mmall_admin_fe)/dist / view /* { 
        deny all; 
    } 
    location / { 
        root C:\ftpfile\img; 
        add_header Access-Control-Allow-Origin *; 
        } 
    }


tomcat.hcxjingdong.com.conf:转向端口的反向代理:
server {
    listen 80;
    autoindex on;
    server_name tomcat.hcxjingdong.com;
    access_log c: /access.log combined; index index.html index.htm index.jsp index.php; #error_page 404 /
    404. html;
    if ($query_string~ * ".*[\;'\].*") {
        return 404;
    }
    location / {
            proxy_pass http: //127.0.0.1:8080; 
            add_header Access-Control-Allow-Origin *; 
            } 
    }

4. Startup (restart) verification
①Startup:

{nginx}/sbin/nginx -s reload

Note: ${ nginx} represents the path installed in the system, for example: /usr/local/nginx

5. Access verification

Use the default port 80 for access verification: http://localhost: 80 or http://127.0.0.1:80

6. Point to port

http forwarding

server{
    listen 80;
    autoindex off;
    server_name learning.hcxjingdong.com;
    access_log c:/access.log combined;
    index index.html index.htm index.jsp index.php;
    #error_page 404 /404.html;
    if ( $query_string ~* ".*[\;'\].*" ){
        return 404;
    }
    location / {
        proxy_pass http://127.0.0.1:81/learning;
        add_header Access-Control-Allow-Origin *;
    }
}

listen 80: listen to port 80;
autoindex off: whether Create an index directory for the homepage;
When nginx receives a request for image.hcxjingdong.com (second-level domain name), it forwards it to: http://127.0.0.1:81/learning directory

7. Point to the directory

Online image server, the front-end deployment server provided for the front end is through the reverse proxy pointing to the directory

server{
    listen 80;
    autoindex off;
    server_name img.hcxjingdong.com;
    access_log c:/access.log combined;
    index index.html index.htm index.jsp index.php;
    #root /product/front/;
    #error_page 404 /404.html;
    if ( $query_string ~* ".*[\;'\].*" ){
        return 404;
    }
    location ~ /(hcxjingdong_fe|hcxmall_admin_fe)/dist/view/* {
        deny all;
    }
    location / {
        root \product\ftpfile\img;
        add_header Access-Control-Allow-Origin *;
    }
}

root /product/ftpfile/img:
root points directly The img folder under the ftpfile under the product folder of the hard disk system directory;
That is, when accessing img.hcxjingdong.com, it directly points to the folder

8. Test verification

Installation and configuration examples of Nginx under Windows

5. Nginx Notes

You can configure domain name forwarding, but please be sure to configure the host and make the host effective. After the setting is completed, restart the browser

Configuration under Windows:
①Enter c:\Windows\System32\drivers\etc
②Open the hosts file with Notepad
③Add the corresponding domain name and IP
④Save and exit

For example:
10.211.55.6 image.hcx.com
10.211.55.6 s.hcx.com

Installation and configuration examples of Nginx under Windows

6. Configure Windows Nginx

Configure hosts:
c:\Windows\System32\drivers\etc

Installation and configuration examples of Nginx under Windows

Use a browser to visit www.hcxjingdong.com

Installation and configuration examples of Nginx under Windows

Including local access to http://localhost:

Installation and configuration examples of Nginx under Windows

Configuration directory forwarding

1. Enter nginx.conf (main configuration of nginx):
Add: include vhost/*.conf;

修改Installation and configuration examples of Nginx under Windows

2. Follow this path to create this folder:
Create the vhost folder under the conf folder

Installation and configuration examples of Nginx under Windows

3. Create the file in the vhost folder: image.hcxjingdong.com.conf

Installation and configuration examples of Nginx under Windows

document content:

server{
    listen 80;
    autoindex off;
    server_name image.hcxjingdong.com;
    access_log c:/access.log combined;
    index index.html index.htm index.jsp index.php;
    #error_page 404 /404.html;
    if ( $query_string ~* ".*[\;'\].*" ){
        return 404;
    }

    location ~ /(hcxmall_fe|hcxmall_admin_fe)/dist/view/* {
        deny all;
    }

    location / {
        root C:\ftpfile\img;
        add_header Access-Control-Allow-Origin *;
    }
}

到C:\ftpfile\img目录下存放图片以便访问

4.修改本机的host,让本机的nginx配合到image.hcxjingdong.com域名

去到C:\Windows\System32\drivers\etc目录下修改hosts文件:

Installation and configuration examples of Nginx under Windows

5.重启nginx:

进入到nginx目录执行命令:
①nginx.exe -t:验证配置文件是否正确
②nginx.exe -s reload:重启nginx

Installation and configuration examples of Nginx under Windows

6.访问域名(image.hcxjingdong.com)验证图片是否生效:

测试host是否生效:image.hcxjingdong.com
测试图片是否生效:http://image.hcxjingdong.com/hcx.jpg

Installation and configuration examples of Nginx under Windows

配置ip端口的转发

1.在conf下的vhost下创建:tomcat.hcxjingdong.com.conf

Installation and configuration examples of Nginx under Windows

使用tomcat域名进行ip端口转发,转发到tomcat服务上

tomcat.hcxjingdong.com.conf:

server{
    listen 80;
    autoindex off;
    server_name tomcat.hcxjingdong.com;
    access_log c:/access.log combined;
    index index.html index.htm index.jsp index.php;
    #error_page 404 /404.html;
    if ( $query_string ~* ".*[\;'\].*" ){
        return 404;
    }
    location / {
        proxy_pass http://127.0.0.1:8080;
        add_header Access-Control-Allow-Origin *;
    }
}

2.配置hosts:

Installation and configuration examples of Nginx under Windows

3.启动tomcat

4.重启nginx:nginx.exe -s reload

5.访问http://tomcat.hcxjingdong.com
成功显示tomcat启动页,说明http的转发也成功了。

相关推荐:

Windows下Nginx的安装与配置

nginx的安装配置

Nginx学习笔记(一):nginx的安装和配置

The above is the detailed content of Installation and configuration examples of Nginx under Windows. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
c盘的users是什么文件夹?可以删除吗?c盘的users是什么文件夹?可以删除吗?Nov 10, 2022 pm 06:20 PM

c盘的users是用户文件夹,主要存放用户的各项配置文件。users文件夹是windows系统的重要文件夹,不能随意删除;它保存了很多用户信息,一旦删除会造成数据丢失,严重的话会导致系统无法启动。

启动任务管理器的三个快捷键是什么启动任务管理器的三个快捷键是什么Sep 21, 2022 pm 02:47 PM

启动任务管理器的三个快捷键是:1、“Ctrl+Shift+Esc”,可直接打开任务管理器;2、“Ctrl+Alt+Delete”,会进入“安全选项”的锁定界面,选择“任务管理器”,即可以打开任务管理器;3、“Win+R”,会打开“运行”窗口,输入“taskmgr”命令,点击“确定”即可调出任务管理器。

微软的pin码是什么微软的pin码是什么Oct 14, 2022 pm 03:16 PM

PIN码是Windows系统为了方便用户本地登录而独立于window账户密码的快捷登录密码,是Windows系统新添加的一套本地密码策略;在用户登陆了Microsoft账户后就可以设置PIN来代替账户密码,不仅提高安全性,而且也可以让很多和账户相关的操作变得更加方便。PIN码只能通过本机登录,无法远程使用,所以不用担心PIN码被盗。

window下报错“php不是内部或外部命令”怎么解决window下报错“php不是内部或外部命令”怎么解决Mar 23, 2023 pm 02:11 PM

对于刚刚开始使用PHP的用户来说,如果在Windows操作系统中遇到了“php不是内部或外部命令”的问题,可能会感到困惑。这个错误通常是由于系统无法识别PHP的路径导致的。在本文中,我将为您提供一些可能会导致这个问题的原因和解决方法,以帮助您快速解决这个问题。

win10自带的onenote是啥版本win10自带的onenote是啥版本Sep 09, 2022 am 10:56 AM

win10自带的onenote是UWP版本;onenote是一套用于自由形式的信息获取以及多用户协作工具,而UWP版本是“Universal Windows Platform”的简称,表示windows通用应用平台,不是为特定的终端设计的,而是针对使用windows系统的各种平台。

windows操作系统的特点包括什么windows操作系统的特点包括什么Sep 28, 2020 pm 12:02 PM

windows操作系统的特点包括:1、图形界面;直观高效的面向对象的图形用户界面,易学易用。2、多任务;允许用户同时运行多个应用程序,或在一个程序中同时做几件事情。3、即插即用。4、出色的多媒体功能。5、对内存的自动化管理。

win10为什么没有“扫雷”游戏了win10为什么没有“扫雷”游戏了Aug 17, 2022 pm 03:37 PM

因为win10系统是不自带扫雷游戏的,需要用户自行手动安装。安装步骤:1、点击打开“开始菜单”;2、在打开的菜单中,找到“Microsoft Store”应用商店,并点击进入;3、在应用商店主页的搜索框中,搜索“minesweeper”;4、在搜索结果中,点击选择需要下载的“扫雷”游戏;5、点击“获取”按钮,等待获取完毕后自动完成安装游戏即可。

在windows中鼠标指针呈四箭头时一般表示什么在windows中鼠标指针呈四箭头时一般表示什么Dec 17, 2020 am 11:39 AM

在windows中鼠标指针呈四箭头时一般表示选中对象可以上、下、左、右移动。在Windows中鼠标指针首次用不同的指针来表示不同的状态,如系统忙、移动中、拖放中;在Windows中使用的鼠标指针文件还被称为“光标文件”或“动态光标文件”。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.