Detailed configuration method for Nginx and Apache Common 80 port

Source: Internet
Author: User
This article mainly introduces the nginx and Apache common 80 port configuration method, of course, if you want Nginx not with Apache Rob 80 port, this article also comes with the Nginx port modification method, the need for friends can refer to the next

A typical Nginx + Apache application scenario can be nginx occupying 80 ports, filtering static requests, and then dynamically requesting the Proxy to the Apache 8080 port. The advantage of proxy reverse proxies is that when access is always 80 port, visitors will not be aware of any difference.

However, some applications are very "smart", recognizing that Apache is located in the port is 8080, will be associated with the hyperlinks are added: 8080 of the follow-up. So you're dead, and you can have a normal visit?!

There is a way to solve this problem, that is, Apache is also running on port 80. The same server, there are nginx also apache,2 a httpd service, are 80, will not conflict?

The below is an example method.
Nginx.conf in the configuration

server {listen; server_name www.webyang.net;}

Modify it a bit.

server {listen 192.168.3.3:80;  #指定Nginx只占用某个IP的80端口. Listen 192.168.10.3:80;  #如果你服务器中有多个IP, you can also specify more than one. server_name www.webyang.net;}

If you have multiple virtual hosts in Nginx, each one needs to be modified.

And then it's Apache's turn to httpd.conf.
Put the original

Listen 80

Switch

Listen 127.0.0.1:80

As with Nginx, specify the IP and port that Apache occupies.
Save to exit and restart Apache to take effect.
If you have more than one virtual host on Apache. No need to modify it as if it were nginx, as long as it is 80 ports.

Such as:

Namevirtualhost *:80<virtualhost *:80> ServerAdmin hello@abc.com documentroot/data/web_server/admin ServerName Www.webyang.net</virtualhost>

Do you think it's all done? Not also.

This Apache can only be accessed through http://127.0.0.1:80, so it doesn't make sense to take up port 80. It's not as good as Apache with 8080,nginx 80.
So at this point if your server has multiple IPs, in addition to the Apache binding in the 127.0.0.1 can also bind another net card IP, then the problem is resolved.

But the average person is only one independent IP, so this method for many people is a mirage.
Modify a way of thinking, Apache or 8080 port, modify one of the Nginx domain name of the Conf file

Location/{try_files $uri @apache, location @apache {internal, proxy_pass http://127.0.0.1:8080;} location ~. *. (PHP|PHP5)? $ {Proxy_pass http://127.0.0.1:8080;}

At this point, the domain name all moves are Apache, including static files.

There are a lot of people who do this:

Upstream Zend {server 127.0.0.1:8080;} location/{proxy_pass  http://zend; 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; Proxy_set_header   x-scheme $scheme;} location ~. *. (PHP|PHP5) $ {proxy_pass  http://zend; 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; Proxy_set_header   x-scheme $scheme;}

Broadly similar.

Nginx Port Modification
Modify the nginx.conf file implementation. The path to the file on Linux is/usr/local/nginx/conf/nginx.conf,windows under install directory \conf\nginx.conf.

server {listen  ; server_name localhost;  ......}

Change into

server {listen  bayi; server_name localhost;  Location/{root HTML; index index.html index.htm;} ...}

Of course change to 8080,8081 anything can, not necessarily 81, but make sure iptable to release access to the port.

Note the configuration of the location:

root HTML; #根目录, relative to the installation directory index index.html index.htm; #默认主页

By default, you can access the files in the HTML folder under the installation directory.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.