如何优雅的安装nginx并启动--windows

简介: 如何优雅的安装nginx并启动--windows

一、下载nginx并解压

网址:http://nginx.org/en/download.html,如下图所示,下载最新windows稳定版。

可直接点击:http://nginx.org/download/nginx-1.18.0.zip

解压压缩包后复制到一个非中文路径,否则无法启动。

2、修改端口启动nginx(80端口经常被其它程序占用,导致无法启动nginx服务)

打开conf文件夹下的nginx.conf文件(建议使用sublime text或者 Visual Studio Code)。

修改端口号,将80修改为8080或8888或81等其它端口,保存文件。

这是我修改的,修改为8081端口

 
#user  nobody;
worker_processes  1;
 
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
 
#pid        logs/nginx.pid;
 
 
events {
    worker_connections  1024;
}
 
 
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_timeout  0;
    keepalive_timeout  65;
 
    #gzip  on;
 
    server {
        listen       8081;
        server_name  localhost;
 
        #charset koi8-r;
 
        #access_log  logs/host.access.log  main;
 
        location / {
            root   html;
            index  index.html index.htm;
        }
 
        #error_page  404              /404.html;
 
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
 
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}
 
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}
 
        # deny access to .htaccess files, if Apache'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 {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;
 
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
 
 
    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    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;
    #    }
    #}
 
}

3、启动nginx服务并测试

运行nginx.exe

在浏览器输入http://localhost:你设置的端口号  如:http://localhost:8081 看到如下画面,恭喜你,成功了。

目录
相关文章
|
1天前
|
应用服务中间件 Linux 程序员
老程序员分享:nginx安装及其配置详细教程
老程序员分享:nginx安装及其配置详细教程
|
1天前
|
应用服务中间件 nginx Docker
Docker安装与管理Nginx
Docker安装与管理Nginx
14 0
|
1天前
|
Dart 开发工具 Android开发
在 Windows 操作系统上安装和配置 Flutter 开发环境
在 Windows 操作系统上安装和配置 Flutter 开发环境
7 0
|
2天前
|
虚拟化 Windows
Windows 11安装Hyper-V
Windows 11安装Hyper-V
9 0
|
2天前
|
Linux 虚拟化 Docker
Docker在windows安装(Win11,docker20.10.23)
Docker在windows安装(Win11,docker20.10.23)
21 0
|
3天前
|
Windows
zookeeper-3.8.0安装(Windows)
zookeeper-3.8.0安装(Windows)
12 0
|
3天前
|
应用服务中间件 nginx
centos7.6安装Nginx解决403
centos7.6安装Nginx解决403
11 0
|
3天前
|
Linux Windows
windows和linux安装Erlang
windows和linux安装Erlang
25 0
|
Web App开发 应用服务中间件 nginx
windows下Nginx反向代理服务器安装与配置
感谢慕课网Geely老师的讲解,本人将Nginx进行如下的总结。 Nginx是一款轻量级的Web服务器,也是一款反向代理服务器,其主要特点:高稳定, 高性能,资源占用少功能丰富,模块化结构 支持热部署。
4025 0
|
应用服务中间件 nginx Windows