logo头像

Just open your eyes , you got everything in the world

Nginx快速开端口

本文于462天之前发表,文中内容可能已经过时。

对于一个前端来说,运行一些代码有些特殊情况需要开设端口。起初我使用静态服务器用sumlime,后面陆续使用wampserver,xampp;但是有一次换电脑了,需要重新下载,糟糕的的是突然下载不了,项目于是停止不前;庆幸的是以为Java同事告诉我用Nginx开设端口。我在这里把我这个方法分享给大家!

第一步下载Nginx

下载地址:http://nginx.org/

第二步配置config

进入conf/nignx.conf文件具体配置如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
    #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 80; #端口
server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
root F:\GitMap1\echarts3-chinese-map-drill-down; #真实路径
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;
#}
}

server {
listen 8000; #端口

server_name localhost;

location / {
root F:\GitMap1\echarts3-chinese-map-drill-down; #真实路径
index index.html index.htm;
}
}

server {
listen 8080;

server_name localhost;

location / {
root F:\NewRequest\jingqingan_ganzhou;
index index.html index.htm;
}
}
# 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;
# }
#}

}

Windows下使用nginx命令启动

在Windows下使用Nginx,我们需要掌握一些基本的操作命令,比如:启动、停止Nginx服务,重新载入Nginx等,下面我就进行一些简单的介绍。

启动

1
2
3
4
5
C:\server\nginx-1.0.2>start nginx



C:\server\nginx-1.0.2>nginx.exe

注:建议使用第一种,第二种会使你的cmd窗口一直处于执行中,不能进行其他命令操作。

停止

1
2
3
4
5
C:\server\nginx-1.0.2>nginx.exe -s stop



C:\server\nginx-1.0.2>nginx.exe -s quit

注:stop是快速停止nginx,可能并不保存相关信息;quit是完整有序的停止nginx,并保存相关信息。

重新载入Nginx

1
C:\server\nginx-1.0.2>nginx.exe -s reload

当配置信息修改,需要重新载入这些配置时使用此命令。

重新打开日志文件:

1
C:\server\nginx-1.0.2>nginx.exe -s reopen

查看Nginx版本:

1
C:\server\nginx-1.0.2>nginx -v
载入天数...载入时分秒...
很荣幸您成为本站的第 位访客   |   本站总浏览次数: