最近项目前后端分离调试的时候要请求服务器上的项目,就整了nginx去用,接下来看代码
强烈注释:nginx启动一闪而过不是报错,去资源管理器——详细信息——输入n查看进程,有的话启动成功。没有去看error.log日志,看端口号被占用还是什么原因。
nginx 下载链接https://pan.baidu.com/s/1I1p3seChzwT7zpWMVOnBvg
提取码:8er0
大家根据自己项目要记得修改conf下的nginx配置,也就是这个
#全局配置 #user nobody nobody; 指定可以运行nginx服务器的用户和组,不配置默认 #user nobody; #指定nginx要开启的进程数 worker_processes 1; #错误日志存放路径 #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #nginx进程PID存放路径,保存当前运行程序主进程号,不指定默认 #pid logs/nginx.pid; #events 设定nginx的工作模式及连接数上限 events { #工作模式支持的有elect、poll、kqueue、epoll、rtsig和/dev/poll 。 #其中select 和poll 都是标准的工作模式,kqueue和epoll是高效的工作模式,不同的是epoll用在Linux平台上, #而kqueue用在BSD系统中。对于Linux系统,epoll工作模式是首选。例: #use epoll #定义每个进程连接数上限 worker_connections 1024; } http { #该指令主要用于将其他的Nginx配置或第三方模块的配置引用到当前的主配文件中,减少主配置文件的复杂度 include mime.types; #设定默认类型为二进制流,当文件类型未定义时使用这种方式 default_type application/octet-stream; #log_format 是Nginx的HttpLog模块指令,用于指定Nginx日志的输出日志 #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方式传输文件 sendfile on; #tcp_nopush on; #连接超时时间 #keepalive_timeout 0; keepalive_timeout 65; #gzip on; #server(主机设置):指令主要用于指定主机和端口 server { #监听的端口 listen 8012; #server_name 用来指定IP地址或域名,多个域名之间用空格分开 server_name localhost; #http://127.0.0.1 http://1.71.12.14/ #index用于设定访问的默认首页地址 #root指令用于指定虚拟主机的网页根目录,这个目录可以是相对路径,也可以是绝对路径。 #charset用于设置网页的默认编码格式。 #access_log 用来指定虚拟主机的访问日志存放路径,最后的main 用于指定访问日志的输出格式。 #charset koi8-r; #access_log logs/host.access.log main; #(URL匹配特定位置的设置):用于匹配网页位置 #URL地址匹配是进行Nginx配置中最灵活的部分。 #location支持正则表达式匹配,也支持条件判断匹配,用户可以通过location指令实现Nginx对动、静态网页进行过滤处理。 #使用location URL匹配配置还可以实现反向代理,用于实现PHP动态解析或者负载负载均衡。 location /front/{ #当访问/front/ 时跳转的地址变为http://1.71.12.14:8012/front/; #此处可以配置hrrp://www.baidu.com测试 proxy_pass http://1.71.12.14:8012; add_header Access-Control-Allow-Origin *; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Server $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Cookie $http_cookie; } location /{ #root指令用于指定虚拟主机的网页根目录,这个目录可以是相对路径,也可以是绝对路径 #然后浏览器敲loclhost:8012就可以访问了login.html root E:/Meteringequipment; #index 设置访问首页 index login.html; } #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; # } #} }去上层启动nginx.exe,或者命令行start nginx.exe
项目启动后去资源管理器下面看是否有启动进程,没有话去logs里看error.log
有显示8080 is already 之类的就是端口被占用,换一个像listen 8888
其他的就看自己的了