search
HomeBackend DevelopmentPHP TutorialNginx configuration summary

Modify the nginx server configuration, the nginx.conf file under the conf file.

<code><span>#user nobody;   #运行用户</span><span>#worker_processes 1;    #启动进程数,通常设置成和cpu数目相同</span><span>#error_log /var/log;    #错误日志</span>
events {
    worker_connections <span>1024</span>;<span>#单个后台work process进程最大并发链接数</span>
}

<span>#设定http服务器</span>
http{
     <span>#设定mime类型,类型由mime.type文件定义</span>
    include       /etc/nginx/mime.types;
    default_type  <span>application</span>/octet-stream;
    <span>#设定日志格式</span>
    access_log    /var/<span>log</span>/nginx/access.<span>log</span>;
    sendfile <span><span>on</span></span>;
    <span>#连接超时时间</span><span>#keepalive_timeout  0;</span>
    keepalive_timeout  <span>65</span>;
    tcp_nodelay        <span><span>on</span></span>;

    <span>#集群中的所有后台服务器的配置信息,用于负载均衡</span>
    upstream local_tomcat{
        server <span>192.168</span><span>.0</span><span>.111</span>:<span>80</span>;
        server <span>192.168</span><span>.0</span><span>.109</span>:<span>8080</span>;
    }
    server{
        listen <span>8090</span>;    <span>#当前代理服务器监听端口</span>
        server_name  localhost:<span>80</span>;  <span>#监听后要转到地址</span><span>#charset koi8-r;</span><span>#access_log  logs/host.access.log  main;</span>        location / {    <span>#location表示匹配路径,/表示所有请求</span>
        root   html;  <span>#静态文件存放的路径</span>
        index  index.html index.htm;  <span>#没有主页时,此为主页,可多个</span>
        }

        <span>#error_page  404              /404.html;</span><span># redirect server error pages to the static page/50x.html</span>
        error_page   <span>500</span><span>502</span><span>503</span><span>504</span>  /<span>50</span>x.html;
        location = /<span>50</span>x.html {
            root   html;
        }
    }
}
</code>

Summary of frequently asked questions:
1. nginx+tomcat affects the request value
request.getScheme() //always http, not actual http or https
request.isSecure() //always false (because always http)
request.getRemoteAddr() //Always the IP requested by nginx, not the user’s IP
request.getRequestURL() //Always the URL requested by nginx rather than the URL actually requested by the user
request.getServerName //Always the IP requested by nginx
request.getServerPort //Always the port requested by nginx
response.sendRedirect(relative url) //Always redirect to http (because it is considered to be an http request)
Solution:
Modify nginx configuration:

<code>proxy_<span>set</span>_header Host <span>$host</span>;   <span>#解决getRequestURL、getServerName、getServerPort问题</span>
proxy_<span>set</span>_header X-Real-IP <span>$remote_addr</span>;<span>#把真实的ip发送给转发的web服务器</span>
proxy_<span>set</span>_header X-Forwarded-For <span>$proxy_add_x_forwarded_for</span>;<span>#解决request.getScheme()只能返回http而不是https问题</span></code>

Configure the Engine module of tomcat's server.

The above has introduced a summary of Nginx configuration, including various aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP Email: Step-by-Step Sending GuidePHP Email: Step-by-Step Sending GuideMay 09, 2025 am 12:14 AM

PHPisusedforsendingemailsduetoitsintegrationwithservermailservicesandexternalSMTPproviders,automatingnotificationsandmarketingcampaigns.1)SetupyourPHPenvironmentwithawebserverandPHP,ensuringthemailfunctionisenabled.2)UseabasicscriptwithPHP'smailfunct

How to Send Email via PHP: Examples & CodeHow to Send Email via PHP: Examples & CodeMay 09, 2025 am 12:13 AM

The best way to send emails is to use the PHPMailer library. 1) Using the mail() function is simple but unreliable, which may cause emails to enter spam or cannot be delivered. 2) PHPMailer provides better control and reliability, and supports HTML mail, attachments and SMTP authentication. 3) Make sure SMTP settings are configured correctly and encryption (such as STARTTLS or SSL/TLS) is used to enhance security. 4) For large amounts of emails, consider using a mail queue system to optimize performance.

Advanced PHP Email: Custom Headers & FeaturesAdvanced PHP Email: Custom Headers & FeaturesMay 09, 2025 am 12:13 AM

CustomheadersandadvancedfeaturesinPHPemailenhancefunctionalityandreliability.1)Customheadersaddmetadatafortrackingandcategorization.2)HTMLemailsallowformattingandinteractivity.3)AttachmentscanbesentusinglibrarieslikePHPMailer.4)SMTPauthenticationimpr

Guide to Sending Emails with PHP & SMTPGuide to Sending Emails with PHP & SMTPMay 09, 2025 am 12:06 AM

Sending mail using PHP and SMTP can be achieved through the PHPMailer library. 1) Install and configure PHPMailer, 2) Set SMTP server details, 3) Define the email content, 4) Send emails and handle errors. Use this method to ensure the reliability and security of emails.

What is the best way to send an email using PHP?What is the best way to send an email using PHP?May 08, 2025 am 12:21 AM

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

Best Practices for Dependency Injection in PHPBest Practices for Dependency Injection in PHPMay 08, 2025 am 12:21 AM

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHP performance tuning tips and tricksPHP performance tuning tips and tricksMay 08, 2025 am 12:20 AM

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.

PHP Email Security: Best Practices for Sending EmailsPHP Email Security: Best Practices for Sending EmailsMay 08, 2025 am 12:16 AM

ThebestpracticesforsendingemailssecurelyinPHPinclude:1)UsingsecureconfigurationswithSMTPandSTARTTLSencryption,2)Validatingandsanitizinginputstopreventinjectionattacks,3)EncryptingsensitivedatawithinemailsusingOpenSSL,4)Properlyhandlingemailheaderstoa

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version