NutzCN Logo
问答 nginx配置tomcat启动后报错
发布于 162天前 作者 quinnxiao 320 次浏览 复制 上一个帖子 下一个帖子
标签: nginx

nginx的配置文件

#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;  
  
    upstream web_app{  
        server 192.168.84.130:8080 max_fails=2 fail_timeout=30s weight=1;  
        server 192.168.84.131:8080 max_fails=2 fail_timeout=30s weight=1;  
    }  
      
    server {  
        listen       80;  
        server_name  localhost;  
  
        #charset koi8-r;  
  
        #access_log  logs/host.access.log  main;  
  
        location / {  
            root   html;  
			#定义首页索引文件的名称
            index  index.html index.htm index.jsp login.jsp;   
			#请求转向suroot定义的服务器列表  
            proxy_pass http://web_app;
            #以下是一些反向代理的配置可删除.  
            proxy_redirect off;  
            proxy_set_header   Host $host;  
            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   128k;#缓冲区代理缓冲用户端请求的最大字节数,  
            proxy_connect_timeout   600;#nginx跟后端服务器连接超时时间(代理连接超时)  
            proxy_send_timeout   600; #后端服务器数据回传时间(代理发送超时)  
            proxy_read_timeout   600; #连接成功后,后端服务器响应时间(代理接收超时)  
            proxy_buffer_size   8k; #设置代理服务器(nginx)保存用户头信息的缓冲区大小  
            proxy_buffers   4 64k;#proxy_buffers缓冲区,网页平均在32k以下的话,这样设置  
            proxy_busy_buffers_size   128k;#高负荷下缓冲大小(proxy_buffers*2)  
            proxy_temp_file_write_size  128k;#设定缓存文件夹大小,大于这个值,将从upstream服务器传  
        }  
  
        #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启动后的状态

[root@localhost nginx]# systemctl start nginx
[root@localhost nginx]# systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/nginx.service.d
           └─override.conf
   Active: active (running) since 六 2018-04-14 14:28:53 CST; 5s ago
  Process: 11778 ExecStartPost=/bin/sleep 0.1 (code=exited, status=0/SUCCESS)
  Process: 11775 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 11773 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 11772 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 11777 (nginx)
   CGroup: /system.slice/nginx.service
           ├─11777 nginx: master process /usr/sbin/nginx
           └─11779 nginx: worker process

4月 14 14:28:53 localhost.localdomain systemd[1]: Starting The nginx HTTP and reverse proxy server...
4月 14 14:28:53 localhost.localdomain nginx[11773]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
4月 14 14:28:53 localhost.localdomain nginx[11773]: nginx: configuration file /etc/nginx/nginx.conf test is successful
4月 14 14:28:53 localhost.localdomain systemd[1]: Started The nginx HTTP and reverse proxy server.

在浏览器中打开报错

nginx error!
The page you are looking for is temporarily unavailable. Please try again later.
Website Administrator
Something has triggered an error on your website. This is the default error page for nginx that is distributed with Fedora. It is located /usr/share/nginx/html/50x.html

You should customize this error page for your own site or edit the error_page directive in the nginx configuration file /etc/nginx/nginx.conf.

http://192.168.84.130:8080/
http://192.168.84.131:8080/
这两台分别是我在虚拟机中tomcat的路劲

14 回复

主机地址是能够ping通的

[root@localhost nginx]# ping 192.168.84.130
PING 192.168.84.130 (192.168.84.130) 56(84) bytes of data.
64 bytes from 192.168.84.130: icmp_seq=1 ttl=64 time=0.283 ms
64 bytes from 192.168.84.130: icmp_seq=2 ttl=64 time=0.333 ms
64 bytes from 192.168.84.130: icmp_seq=3 ttl=64 time=0.450 ms
^C
--- 192.168.84.130 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 0.283/0.355/0.450/0.071 ms
[root@localhost nginx]# ping 192.168.84.131
PING 192.168.84.131 (192.168.84.131) 56(84) bytes of data.
64 bytes from 192.168.84.131: icmp_seq=1 ttl=64 time=0.199 ms
64 bytes from 192.168.84.131: icmp_seq=2 ttl=64 time=0.456 ms
64 bytes from 192.168.84.131: icmp_seq=3 ttl=64 time=0.502 ms
^C
--- 192.168.84.131 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2001ms
rtt min/avg/max/mdev = 0.199/0.385/0.502/0.135 ms
[root@localhost nginx]# 

2018/04/14 15:08:24 [notice] 12038#0: signal process started
2018/04/14 15:08:28 [crit] 12039#0: *51 connect() to 192.168.84.130:8080 failed (13: Permission denied) while connecting to upstream, client: 192.168.84.1, server: _, request: "GET / HTTP/1.1", upstream: "http://192.168.84.130:8080/", host: "192.168.84.129"
2018/04/14 15:08:28 [crit] 12039#0: *51 connect() to 192.168.84.130:8080 failed (13: Permission denied) while connecting to upstream, client: 192.168.84.1, server: _, request: "GET / HTTP/1.1", upstream: "http://192.168.84.130:8080/", host: "192.168.84.129"
2018/04/14 15:08:28 [crit] 12039#0: *51 connect() to 192.168.84.130:8080 failed (13: Permission denied) while connecting to upstream, client: 192.168.84.1, server: _, request: "GET / HTTP/1.1", upstream: "http://192.168.84.130:8080/", host: "192.168.84.129"
2018/04/14 15:08:29 [crit] 12039#0: *51 connect() to 192.168.84.130:8080 failed (13: Permission denied) while connecting to upstream, client: 192.168.84.1, server: _, request: "GET / HTTP/1.1", upstream: "http://192.168.84.130:8080/", host: "192.168.84.129"
2018/04/14 15:09:32 [crit] 12039#0: *51 connect() to 192.168.84.130:8080 failed (13: Permission denied) while connecting to upstream, client: 192.168.84.1, server: _, request: "GET / HTTP/1.1", upstream: "http://192.168.84.130:8080/", host: "192.168.84.129"

centos7毒瘤系统?

来自炫酷的 NutzCN

我在网上下载的contos7
这个地址下载的
http://101.110.118.27/isoredirect.centos.org/centos/7/isos/x86_64/CentOS-7-x86_64-DVD-1708.iso

选的阿里云的
http://mirrors.aliyun.com/centos/7/isos/x86_64/CentOS-7-x86_64-DVD-1708.iso
这应该没问题吧
配了一天,怎么配怎么不行,但是两台tomcat都是可以启动并且能访问,放到nginx就不行了

把它格了装ubuntu

来自炫酷的 NutzCN

啊,不会吧,我晕死啊,我是虚拟机装的

毒瘤centos7不是浪得虚名的

好吧,我是想我正式服务器的nginx是centos的,想弄个测试环境接近点,我再装个ubuntu试下

把正式服务器也格了

那不可能咯,我正式服务器是阿里云的已经再跑了呢,运维的人买的我也不清楚,反正nginx是在跑没问题,我想自己弄个试下

大叔让你格你就格,怕啥 @quinnxiao

setsebool -P httpd_can_network_connect 1
在nginx所在的主机输入这条命令就好了,不用装ubuntu,嘿嘿

添加回复
请先登陆
回到顶部