Rumah > pembangunan bahagian belakang > tutorial php > 使用nginx反向代理tomcat服务

使用nginx反向代理tomcat服务

WBOY
Lepaskan: 2016-07-29 08:55:30
asal
1705 orang telah melayarinya

使用nginx反向代理tomcat服务
本次的实验需要nginx服务和tomcat服务{具体就不讲怎么安装}

环境:
1.centos6.5
2.iptables和selinux关闭
3.服务全部启动
使用nginx反向代理tomcat服务

思路:通过nginx的配置文件中指定对应的服务。

nginx.conf配置内容:

<code><span>#user  nobody;</span>
worker_processes  <span>2</span><span>;</span><span>#error_log  logs/error.log;</span><span>#error_log  logs/error.log  notice;</span><span>#error_log  logs/error.log  info;</span><span>#pid        logs/nginx.pid;</span>events {
    worker_connections  <span>1024</span><span>;</span>
}


http {
    include       mime<span>.types</span><span>;</span>
    default_type  application/octet-stream<span>;</span><span>#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '</span><span>#                  '$status $body_bytes_sent "$http_referer" '</span><span>#                  '"$http_user_agent" "$http_x_forwarded_for"';</span><span>#access_log  logs/access.log  main;</span>    sendfile        on<span>;</span><span>#tcp_nopush     on;</span><span>#keepalive_timeout  0;</span>
    keepalive_timeout  <span>65</span><span>;</span><span>#gzip  on;</span><span>#   server {</span><span>#       listen       80;</span><span>#       server_name  shinyv.cc.com;</span><span>#charset koi8-r;</span><span>#access_log  logs/host.access.log  main;</span><span>#       location / {</span><span>#           root   html;</span><span>#           index  index.html index.htm;</span><span>#       }</span><span>#error_page  404              /404.html;</span><span># redirect server error pages to the static page /50x.html</span><span>#</span><span>#       error_page   500 502 503 504  /50x.html;</span><span>#       location = /50x.html {</span><span>#           root   html;</span><span>#      }</span><span># proxy the PHP scripts to Apache listening on 127.0.0.1:80</span><span>#</span><span>#location ~ \.php$ {</span><span>#    proxy_pass   http://127.0.0.1;</span><span>#}</span><span># pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000</span><span>#</span><span>#location ~ \.php$ {</span><span>#    root           html;</span><span>#    fastcgi_pass   127.0.0.1:9000;</span><span>#    fastcgi_index  index.php;</span><span>#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;</span><span>#    include        fastcgi_params;</span><span>#}</span><span># deny access to .htaccess files, if Apache's document root</span><span># concurs with nginx's one</span><span>#</span><span>#location ~ /\.ht {</span><span>#    deny  all;</span><span>#}</span><span>#   }</span>    upstream  tomcat_web {
        server  <span>192.168</span><span>.140</span><span>.19</span>:<span>8080</span><span>;</span>
        }   
    server {
            listen <span>80</span><span>;</span>
            server_name         cui<span>.youfang</span><span>.com</span><span>;</span>
            access_log      /var/log/nginx/cui<span>.youfang</span><span>.access</span><span>.log</span><span>;</span>
            error_log       /var/log/nginx/cui<span>.youfang</span><span>.error</span><span>.log</span><span>;</span>            location / {
                proxy_set_header    Host $host<span>;</span>
                proxy_set_header    <span>Set</span>-Cookie $http_cookie<span>;</span>
                proxy_set_header    <span>X</span>-Real-Ip $remote_addr<span>;</span>
                proxy_set_header    <span>X</span>-Forwarded-For $remote_addr<span>;</span>
                proxy_pass    http://tomcat_web<span>;        </span>
            }
    }
    <span># another virtual host using mix of IP-, name-, and port-based configuration</span><span>#</span><span>#server {</span><span>#    listen       8000;</span><span>#    listen       somename:8080;</span><span>#    server_name  somename  alias  another.alias;</span><span>#    location / {</span><span>#        root   html;</span><span>#        index  index.html index.htm;</span><span>#    }</span><span>#}</span><span># HTTPS server</span><span>#</span><span>#server {</span><span>#    listen       443 ssl;</span><span>#    server_name  localhost;</span><span>#    ssl_certificate      cert.pem;</span><span>#    ssl_certificate_key  cert.key;</span><span>#    ssl_session_cache    shared:SSL:1m;</span><span>#    ssl_session_timeout  5m;</span><span>#    ssl_ciphers  HIGH:!aNULL:!MD5;</span><span>#    ssl_prefer_server_ciphers  on;</span><span>#    location / {</span><span>#        root   html;</span><span>#        index  index.html index.htm;</span><span>#    }</span><span>#}</span>}
</code>
Salin selepas log masuk

改完配置需要对nginx进行重启
应为是基于域名进行绑定的所以需要绑定hosts:
使用nginx反向代理tomcat服务

之后在本机PC上的hosts中绑定:
使用nginx反向代理tomcat服务

这样就完成了;现在可以进行测试啦!

测试:

是否可以用IP访问
使用nginx反向代理tomcat服务

用域名直接打开
使用nginx反向代理tomcat服务

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

以上就介绍了使用nginx反向代理tomcat服务,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan